JUNGU commited on
Commit
f049b45
โ€ข
1 Parent(s): 00715ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -56
app.py CHANGED
@@ -30,63 +30,67 @@ def main():
30
  with col2:
31
  user_input = st.text_input("๋ชจ๋ฅด๋Š” ๋ฌธ์žฅ์ด๋‚˜ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”:", "")
32
 
33
- if st.button("ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ"):
34
- 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:
35
- annotated_text(
36
- "This ",
37
- ("is", ""),
38
- " some ",
39
- ("annotated", ""),
40
- ("text", ""),
41
- " for those of ",
42
- ("you", ""),
43
- " who ",
44
- ("like", ""),
45
- " this sort of ",
46
- ("thing", ""),
47
- ". "
48
- )"""
 
 
49
 
50
- user_prompt = f"First, extract key words for the topic st-annotated-text format.: {user_text}"
51
-
52
- messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
53
-
54
- response = openai.ChatCompletion.create(
55
- model="gpt-3.5-turbo-16k",
56
- messages=messages,
57
- temperature=0.1,
58
- max_tokens=2500,
59
- top_p=0.2,
60
- frequency_penalty=0,
61
- presence_penalty=0
62
- )
63
-
64
- highlighted_text = response['choices'][0]['message']['content']
65
-
66
- exec(highlighted_text)
67
-
68
- # ์ถ”๊ฐ€ ์„ค๋ช… ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ถ”๊ฐ€์ ์ธ ์„ค๋ช…์„ ํ•ด์คŒ
69
- if st.button("์ถ”๊ฐ€ ์„ค๋ช…"):
70
- # ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ ์„ค๋ช…
71
- explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {user_text}"
72
-
73
- messages = [
74
- {"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"},
75
- {"role": "user", "content": explanation_task}
76
- ]
77
-
78
- response = openai.ChatCompletion.create(
79
- model="gpt-3.5-turbo-16k",
80
- messages=messages,
81
- temperature=0.1,
82
- max_tokens=150
83
- )
84
-
85
- explanation = response['choices'][0]['message']['content']
 
86
 
87
- # ์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
88
- st.text("์„ค๋ช…:")
89
- st.write(explanation)
90
-
 
91
  if __name__ == "__main__":
92
  main()
 
30
  with col2:
31
  user_input = st.text_input("๋ชจ๋ฅด๋Š” ๋ฌธ์žฅ์ด๋‚˜ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”:", "")
32
 
33
+ cols = st.columns(2)
34
+ with cols[0]:
35
+ if st.button("ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ"):
36
+ 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:
37
+ annotated_text(
38
+ "This ",
39
+ ("is", ""),
40
+ " some ",
41
+ ("annotated", ""),
42
+ ("text", ""),
43
+ " for those of ",
44
+ ("you", ""),
45
+ " who ",
46
+ ("like", ""),
47
+ " this sort of ",
48
+ ("thing", ""),
49
+ ". "
50
+ )"""
51
 
52
+ user_prompt = f"First, extract key words for the topic st-annotated-text format.: {user_text}"
53
+
54
+ messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
55
+
56
+ response = openai.ChatCompletion.create(
57
+ model="gpt-3.5-turbo-16k",
58
+ messages=messages,
59
+ temperature=0.1,
60
+ max_tokens=2500,
61
+ top_p=0.2,
62
+ frequency_penalty=0,
63
+ presence_penalty=0
64
+ )
65
+
66
+ highlighted_text = response['choices'][0]['message']['content']
67
+
68
+ exec(highlighted_text)
69
+ pass
70
+
71
+ with cols[1]:
72
+ if st.button("์ถ”๊ฐ€ ์„ค๋ช…"):
73
+ # ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ ์„ค๋ช…
74
+ explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {user_text}"
75
+
76
+ messages = [
77
+ {"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"},
78
+ {"role": "user", "content": explanation_task}
79
+ ]
80
+
81
+ response = openai.ChatCompletion.create(
82
+ model="gpt-3.5-turbo-16k",
83
+ messages=messages,
84
+ temperature=0.1,
85
+ max_tokens=150
86
+ )
87
+
88
+ explanation = response['choices'][0]['message']['content']
89
 
90
+ # ์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
91
+ st.text("์„ค๋ช…:")
92
+ st.write(explanation)
93
+ pass
94
+
95
  if __name__ == "__main__":
96
  main()