ginipick commited on
Commit
9f9f91f
ยท
verified ยท
1 Parent(s): 99be49b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -1032,6 +1032,53 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
1032
 
1033
  return history
1034
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1035
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
1036
  with gr.Tabs():
1037
  # ๊ตญ๊ฐ€๋ณ„ ํƒญ
 
1032
 
1033
  return history
1034
 
1035
+
1036
+ def continue_writing(history, system_message, max_tokens, temperature, top_p):
1037
+ if not history:
1038
+ return history
1039
+
1040
+ last_response = history[-1][1] if history else ""
1041
+ continue_prompt = f"""์ด์ „ ๋‚ด์šฉ์„ ์ด์–ด์„œ ๊ณ„์† ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
1042
+ ๋งˆ์ง€๋ง‰ ์‘๋‹ต: {last_response}
1043
+
1044
+ ์ถ”๊ฐ€ ์ง€์นจ:
1045
+ 1. ์ด์ „ ๋‚ด์šฉ์˜ ๋งฅ๋ฝ์„ ์œ ์ง€ํ•˜๋ฉฐ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ด์–ด์„œ ์ž‘์„ฑ
1046
+ 2. ์ƒˆ๋กœ์šด ์ •๋ณด๋‚˜ ์ƒ์„ธ ์„ค๋ช…์„ ์ถ”๊ฐ€
1047
+ 3. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ณด์ถฉ ์„ค๋ช…์ด๋‚˜ ๋ถ„์„ ์ œ๊ณต
1048
+ 4. ๊ธฐ์‚ฌ ํ˜•์‹๊ณผ ์Šคํƒ€์ผ ์œ ์ง€
1049
+ 5. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ถ”๊ฐ€์ ์ธ ์ด๋ฏธ์ง€ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
1050
+ """
1051
+
1052
+ messages = [
1053
+ {"role": "system", "content": system_message},
1054
+ {"role": "assistant", "content": last_response},
1055
+ {"role": "user", "content": continue_prompt}
1056
+ ]
1057
+
1058
+ try:
1059
+ full_response = ""
1060
+ for message in client.chat.completions.create(
1061
+ model="CohereForAI/c4ai-command-r-plus-08-2024",
1062
+ max_tokens=max_tokens,
1063
+ stream=True,
1064
+ temperature=temperature,
1065
+ top_p=top_p,
1066
+ messages=messages,
1067
+ ):
1068
+ if hasattr(message.choices[0].delta, 'content'):
1069
+ token = message.choices[0].delta.content
1070
+ if token:
1071
+ full_response += token
1072
+ history.append(("๊ณ„์† ์ž‘์„ฑ", full_response))
1073
+ yield history
1074
+
1075
+ except Exception as e:
1076
+ error_message = f"๊ณ„์† ์ž‘์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
1077
+ history.append(("์˜ค๋ฅ˜", error_message))
1078
+ yield history
1079
+
1080
+ return history
1081
+
1082
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
1083
  with gr.Tabs():
1084
  # ๊ตญ๊ฐ€๋ณ„ ํƒญ