Update app.py
Browse files
app.py
CHANGED
@@ -39,62 +39,103 @@ def main():
|
|
39 |
|
40 |
if btn_keyword:
|
41 |
# ํค์๋ ์ฐพ๊ธฐ ๋ก์ง
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
|
|
|
|
|
|
44 |
response = openai.ChatCompletion.create(
|
45 |
model="gpt-3.5-turbo-16k",
|
46 |
-
|
47 |
temperature=0.1,
|
48 |
-
max_tokens=
|
|
|
|
|
|
|
49 |
)
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
54 |
|
55 |
if btn_explanation:
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
response = openai.ChatCompletion.create(
|
60 |
model="gpt-3.5-turbo-16k",
|
61 |
-
|
62 |
temperature=0.1,
|
63 |
max_tokens=200
|
64 |
)
|
65 |
-
|
|
|
66 |
|
67 |
-
|
68 |
-
st.write(f"์ค๋ช
: {explanation}")
|
|
|
|
|
69 |
|
70 |
if btn_simple:
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
74 |
response = openai.ChatCompletion.create(
|
75 |
model="gpt-3.5-turbo-16k",
|
76 |
-
|
77 |
temperature=0.1,
|
78 |
-
max_tokens=
|
79 |
)
|
80 |
-
|
81 |
-
|
82 |
-
st.write(f"์ฌ์ด ํํ: {simple_text}")
|
83 |
|
|
|
|
|
|
|
|
|
84 |
if btn_rewrite:
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
87 |
|
88 |
response = openai.ChatCompletion.create(
|
89 |
model="gpt-3.5-turbo-16k",
|
90 |
-
|
91 |
temperature=0.1,
|
92 |
-
max_tokens=
|
93 |
)
|
94 |
-
rewritten_text = response['choices'][0]['text']
|
95 |
|
96 |
-
|
97 |
-
|
|
|
98 |
|
99 |
if __name__ == "__main__":
|
100 |
main()
|
|
|
39 |
|
40 |
if btn_keyword:
|
41 |
# ํค์๋ ์ฐพ๊ธฐ ๋ก์ง
|
42 |
+
task_description ="""You are a useful helper that generates annotated text for Python's st-annotated-text library. Your task is to identify the topic of the passage and highlight the key words needed to convey the meaning. You should be able to identify the main points. Also, please mark keywords based on the different paragraphs and headings provided in the text. The output should be formatted in the following way:
|
43 |
+
annotated_text(
|
44 |
+
"This ",
|
45 |
+
("is", ""),
|
46 |
+
" some ",
|
47 |
+
("annotated", ""),
|
48 |
+
("text", ""),
|
49 |
+
" for those of ",
|
50 |
+
("you", ""),
|
51 |
+
" who ",
|
52 |
+
("like", ""),
|
53 |
+
" this sort of ",
|
54 |
+
("thing", ""),
|
55 |
+
". "
|
56 |
+
)"""
|
57 |
|
58 |
+
user_prompt = f"First, extract key words for the topic st-annotated-text format.: {user_text}"
|
59 |
+
|
60 |
+
messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
|
61 |
+
|
62 |
response = openai.ChatCompletion.create(
|
63 |
model="gpt-3.5-turbo-16k",
|
64 |
+
messages=messages,
|
65 |
temperature=0.1,
|
66 |
+
max_tokens=2500,
|
67 |
+
top_p=0.2,
|
68 |
+
frequency_penalty=0,
|
69 |
+
presence_penalty=0
|
70 |
)
|
71 |
+
|
72 |
+
highlighted_text = response['choices'][0]['message']['content']
|
73 |
+
|
74 |
+
exec(highlighted_text)
|
75 |
+
pass
|
76 |
+
|
77 |
|
78 |
if btn_explanation:
|
79 |
+
explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {user_text}"
|
80 |
+
|
81 |
+
messages = [
|
82 |
+
{"role": "system", "content": "You are a helpful assistant that explains complex topics in a way that an elementary school student can understand. use only korean"},
|
83 |
+
{"role": "user", "content": explanation_task}
|
84 |
+
]
|
85 |
+
|
86 |
response = openai.ChatCompletion.create(
|
87 |
model="gpt-3.5-turbo-16k",
|
88 |
+
messages=messages,
|
89 |
temperature=0.1,
|
90 |
max_tokens=200
|
91 |
)
|
92 |
+
|
93 |
+
explanation = response['choices'][0]['message']['content']
|
94 |
|
95 |
+
# ์ฌ์ด ํํ์ผ๋ก ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
96 |
+
st.write(f"์ถ๊ฐ ์ค๋ช
: {explanation}")
|
97 |
+
pass
|
98 |
+
|
99 |
|
100 |
if btn_simple:
|
101 |
+
explanation_task = f"Describe the fingerprint of '{user_text}' in a way that an elementary school student could understand."
|
102 |
+
|
103 |
+
messages = [
|
104 |
+
{"role": "system", "content": "You are a helpful assistant that explains complex topics in a way that an elementary school student can understand. use only korean"},
|
105 |
+
{"role": "user", "content": explanation_task}
|
106 |
+
]
|
107 |
+
|
108 |
response = openai.ChatCompletion.create(
|
109 |
model="gpt-3.5-turbo-16k",
|
110 |
+
messages=messages,
|
111 |
temperature=0.1,
|
112 |
+
max_tokens=500
|
113 |
)
|
114 |
+
|
115 |
+
explanation = response['choices'][0]['message']['content']
|
|
|
116 |
|
117 |
+
# ์ฌ์ด ํํ์ผ๋ก ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
118 |
+
st.write(f"์ฌ์ด ๊ธ: {explanation}")
|
119 |
+
pass
|
120 |
+
|
121 |
if btn_rewrite:
|
122 |
+
explanation_task = f"Rewrite the contents of '{user_input}' so that it will pass the writing test."
|
123 |
+
|
124 |
+
messages = [
|
125 |
+
{"role": "system", "content": "You are a helpful assistant. use only korean"},
|
126 |
+
{"role": "user", "content": explanation_task}
|
127 |
+
]
|
128 |
|
129 |
response = openai.ChatCompletion.create(
|
130 |
model="gpt-3.5-turbo-16k",
|
131 |
+
messages=messages,
|
132 |
temperature=0.1,
|
133 |
+
max_tokens=1000
|
134 |
)
|
|
|
135 |
|
136 |
+
explanation = response['choices'][0]['message']['content']
|
137 |
+
|
138 |
+
st.write(f"๋ค์ ์ฐ๊ธฐ: {explanation}")
|
139 |
|
140 |
if __name__ == "__main__":
|
141 |
main()
|