JUNGU commited on
Commit
6bd224e
โ€ข
1 Parent(s): 91674d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -29
app.py CHANGED
@@ -39,62 +39,103 @@ def main():
39
 
40
  if btn_keyword:
41
  # ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ ๋กœ์ง
42
- # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
 
 
 
 
44
  response = openai.ChatCompletion.create(
45
  model="gpt-3.5-turbo-16k",
46
- prompt=f"Extract key words from the text: {user_text}",
47
  temperature=0.1,
48
- max_tokens=200
 
 
 
49
  )
50
- keywords = response['choices'][0]['text']
51
-
52
- keywords = "๋ฏผ์ฃผ์ฃผ์˜, ๊ตญ๋ฏผ, ์ •์น˜, ์ฐธ์—ฌ, ๊ถŒ๋ฆฌ, ์ฐธ์ •๊ถŒ, ์„ ๊ฑฐ, ์‚ฌํšŒ ์ง‘๋‹จ, ๋Œ€ํ‘œ์ž, ๊ณต์ง์ž, ๋Œ€ํ‘œ์„ฑ, ํˆฌํ‘œ์œจ, ์ •๋‹น์„ฑ" # ์˜ˆ์‹œ
53
- st.write(f"ํ‚ค์›Œ๋“œ: {keywords}")
 
 
54
 
55
  if btn_explanation:
56
- # ์ถ”๊ฐ€ ์„ค๋ช… ๋กœ์ง
57
- # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.
58
-
 
 
 
 
59
  response = openai.ChatCompletion.create(
60
  model="gpt-3.5-turbo-16k",
61
- prompt=f"Explain the term '{user_input}' in the context of the text: {user_text}",
62
  temperature=0.1,
63
  max_tokens=200
64
  )
65
- explanation = response['choices'][0]['text']
 
66
 
67
- explanation = "์—ฌ๊ธฐ์— ์ถ”๊ฐ€ ์„ค๋ช…์ด ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค." # ์˜ˆ์‹œ
68
- st.write(f"์„ค๋ช…: {explanation}")
 
 
69
 
70
  if btn_simple:
71
- # ์‰ฌ์šด ํ‘œํ˜„ ๋กœ์ง
72
- # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.
73
-
 
 
 
 
74
  response = openai.ChatCompletion.create(
75
  model="gpt-3.5-turbo-16k",
76
- prompt=f"Rewrite the text in simpler terms: {user_text}",
77
  temperature=0.1,
78
- max_tokens=200
79
  )
80
- simple_text = response['choices'][0]['text']
81
- simple_text = "์—ฌ๊ธฐ์— ์‰ฌ์šด ํ‘œํ˜„์ด ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค." # ์˜ˆ์‹œ
82
- st.write(f"์‰ฌ์šด ํ‘œํ˜„: {simple_text}")
83
 
 
 
 
 
84
  if btn_rewrite:
85
- # ๋‹ค์‹œ ์“ฐ๊ธฐ ๋กœ์ง
86
- # OpenAI API ํ˜ธ์ถœ์€ ์‹ค์ œ๋กœ ์‹คํ–‰ํ•˜์‹ค ๋•Œ ์ฃผ์„์„ ํ•ด์ œํ•ด์ฃผ์„ธ์š”.
 
 
 
 
87
 
88
  response = openai.ChatCompletion.create(
89
  model="gpt-3.5-turbo-16k",
90
- prompt=f"Rewrite the text: {user_text}",
91
  temperature=0.1,
92
- max_tokens=200
93
  )
94
- rewritten_text = response['choices'][0]['text']
95
 
96
- rewritten_text = "์—ฌ๊ธฐ์— ๋‹ค์‹œ ์“ด ํ…์ŠคํŠธ๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค." # ์˜ˆ์‹œ
97
- st.write(f"๋‹ค์‹œ ์“ฐ๊ธฐ: {rewritten_text}")
 
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()