JUNGU commited on
Commit
fd2d82a
β€’
1 Parent(s): 6d85b7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -47
app.py CHANGED
@@ -4,6 +4,11 @@ import openai
4
  import os
5
 
6
 
 
 
 
 
 
7
  # OpenAI API μ„€μ • (ν™˜κ²½ λ³€μˆ˜μ—μ„œ μ½μ–΄μ˜΄)
8
  openai.api_key = os.getenv("OPENAI_API_KEY") # μ‹€μ œ μ½”λ“œμ—μ„œ 주석 ν•΄μ œ
9
 
@@ -21,7 +26,7 @@ def main():
21
  반면 의무 νˆ¬ν‘œμ œμ— λ°˜λŒ€ν•˜λŠ” 츑은 ν˜„μž¬ μš°λ¦¬λ‚˜λΌμ˜ νˆ¬ν‘œμœ¨μ΄ μ •μΉ˜ μ§€λ„μžλ“€μ˜ λŒ€ν‘œμ„±μ„ 훼손할 만큼 μ‹¬κ°ν•œ 상황은 μ•„λ‹ˆλΌκ³  μ£Όμž₯ν•œλ‹€. 또 νˆ¬ν‘œμœ¨μ„ λ†’μ΄λŠ” 것보닀 ꡭ민의 μ‹ λ’°λ₯Ό νšŒλ³΅ν•˜λŠ” 것이 더 μ€‘μš”ν•˜κ³ , μ‹œλ―Ό κ΅μœ‘μ΄λ‚˜ λͺ¨μ˜ νˆ¬ν‘œ ꡐ윑 ν”„λ‘œκ·Έλž¨μœΌλ‘œλ„ νˆ¬ν‘œμœ¨ μƒμŠΉμ„ κΈ°λŒ€ν•  수 μžˆλ‹€λ©° 의무 νˆ¬ν‘œμ œμ˜ λ„μž…λ§Œμ΄ νˆ¬ν‘œμœ¨μ΄λ‚˜ μ •μΉ˜μ  관심을 λ†’μ΄λŠ” ν•΄κ²° λ°©μ•ˆμ€ μ•„λ‹ˆλΌκ³  μ΄μ•ΌκΈ°ν•œλ‹€. 그리고 의무 νˆ¬ν‘œμ œλ₯Ό λ„μž…ν•˜λ©΄, μ„ μΆœλœ μ •μΉ˜μΈλ“€μ΄ 높은 νˆ¬ν‘œμœ¨μ„ ν•‘κ³„λ‘œ μ•ˆν•˜λ¬΄μΈμ˜ νƒœλ„λ₯Ό κ°–λŠ” λΆ€μž‘μš©μ΄ 생긴닀든가 ν›„λ³΄μžλ₯Ό 잘 λͺ¨λ₯΄λŠ” μƒνƒœμ—μ„œ νˆ¬ν‘œν•˜λŠ” 일이 λ°œμƒν•˜μ—¬ ꡭ민의 뜻이 였히렀 μ™œκ³‘λ  수 μžˆλ‹€λ©° 우렀의 λͺ©μ†Œλ¦¬λ₯Ό λ‚΄κ³  μžˆλ‹€.
22
  """
23
  st.write(user_text)
24
-
25
  with col2:
26
  user_input = st.text_input("λͺ¨λ₯΄λŠ” λ¬Έμž₯μ΄λ‚˜ 단어λ₯Ό μž…λ ₯ν•˜μ„Έμš”:", "")
27
 
@@ -60,52 +65,28 @@ def main():
60
 
61
  exec(highlighted_text)
62
 
63
- # ν…μŠ€νŠΈ λ²„νŠΌ μΆ”κ°€
64
- if st.button("μΆ”κ°€ μ„€λͺ…"):
65
- # μž…λ ₯된 ν…μŠ€νŠΈ μ„€λͺ…
66
- explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {user_text}"
67
-
68
- messages = [
69
- {"role": "system", "content": "You are a helpful assistant that explains complex topics in a way that an elementary school student can understand."},
70
- {"role": "user", "content": explanation_task}
71
- ]
72
-
73
- response = openai.ChatCompletion.create(
74
- model="gpt-3.5-turbo-16k",
75
- messages=messages,
76
- temperature=0.1,
77
- max_tokens=150
78
- )
79
-
80
- explanation = response['choices'][0]['message']['content']
81
-
82
- # μ‰¬μš΄ ν‘œν˜„μœΌλ‘œ κ²°κ³Ό 좜λ ₯
83
- st.text("μ„€λͺ…:")
84
- st.write(explanation)
85
-
86
- if st.button("μΆ”κ°€ μ„€λͺ…"):
87
- explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {user_text}"
88
-
89
- messages = [
90
- {"role": "system", "content": "You are a helpful assistant that explains complex topics in a way that an elementary school student can understand."},
91
- {"role": "user", "content": explanation_task}
92
- ]
93
-
94
- response = openai.ChatCompletion.create(
95
- model="gpt-3.5-turbo-16k",
96
- messages=messages,
97
- temperature=0.1,
98
- max_tokens=150
99
- )
100
-
101
- explanation = response['choices'][0]['message']['content']
102
-
103
- # μ‰¬μš΄ ν‘œν˜„μœΌλ‘œ κ²°κ³Ό 좜λ ₯
104
- st.text("μ„€λͺ…:")
105
- st.write(explanation)
106
-
107
-
108
 
109
-
 
 
 
110
  if __name__ == "__main__":
111
  main()
 
4
  import os
5
 
6
 
7
+ #지문을 μž…λ ₯ λ°›μ•„μ„œ ν‚€μ›Œλ“œλ§Œ μΆ”μΆœν•˜λŠ” ν•¨μˆ˜
8
+ #λ¬Έλ‹¨μ—μ„œ λͺ¨λ₯΄λŠ” λ‚΄μš©μ„ μΆ”κ°€μ μœΌλ‘œ μ„€λͺ…ν•΄μ€Œ
9
+ #μž…λ ₯창에 μž…λ ₯ν•œ μ§€λ¬Έμ—μ„œ ν‘œν˜„μ„ 닀듬은 글을 μƒμ„±ν•΄μ€Œ gpt3-5-turbo-16k μ‚¬μš©
10
+ #μΆ”κ°€ μ„€λͺ… λ²„νŠΌμ„ λˆ„λ₯΄λ©΄ 좔가적인 μ„€λͺ…을 ν•΄μ€Œ
11
+
12
  # OpenAI API μ„€μ • (ν™˜κ²½ λ³€μˆ˜μ—μ„œ μ½μ–΄μ˜΄)
13
  openai.api_key = os.getenv("OPENAI_API_KEY") # μ‹€μ œ μ½”λ“œμ—μ„œ 주석 ν•΄μ œ
14
 
 
26
  반면 의무 νˆ¬ν‘œμ œμ— λ°˜λŒ€ν•˜λŠ” 츑은 ν˜„μž¬ μš°λ¦¬λ‚˜λΌμ˜ νˆ¬ν‘œμœ¨μ΄ μ •μΉ˜ μ§€λ„μžλ“€μ˜ λŒ€ν‘œμ„±μ„ 훼손할 만큼 μ‹¬κ°ν•œ 상황은 μ•„λ‹ˆλΌκ³  μ£Όμž₯ν•œλ‹€. 또 νˆ¬ν‘œμœ¨μ„ λ†’μ΄λŠ” 것보닀 ꡭ민의 μ‹ λ’°λ₯Ό νšŒλ³΅ν•˜λŠ” 것이 더 μ€‘μš”ν•˜κ³ , μ‹œλ―Ό κ΅μœ‘μ΄λ‚˜ λͺ¨μ˜ νˆ¬ν‘œ ꡐ윑 ν”„λ‘œκ·Έλž¨μœΌλ‘œλ„ νˆ¬ν‘œμœ¨ μƒμŠΉμ„ κΈ°λŒ€ν•  수 μžˆλ‹€λ©° 의무 νˆ¬ν‘œμ œμ˜ λ„μž…λ§Œμ΄ νˆ¬ν‘œμœ¨μ΄λ‚˜ μ •μΉ˜μ  관심을 λ†’μ΄λŠ” ν•΄κ²° λ°©μ•ˆμ€ μ•„λ‹ˆλΌκ³  μ΄μ•ΌκΈ°ν•œλ‹€. 그리고 의무 νˆ¬ν‘œμ œλ₯Ό λ„μž…ν•˜λ©΄, μ„ μΆœλœ μ •μΉ˜μΈλ“€μ΄ 높은 νˆ¬ν‘œμœ¨μ„ ν•‘κ³„λ‘œ μ•ˆν•˜λ¬΄μΈμ˜ νƒœλ„λ₯Ό κ°–λŠ” λΆ€μž‘μš©μ΄ 생긴닀든가 ν›„λ³΄μžλ₯Ό 잘 λͺ¨λ₯΄λŠ” μƒνƒœμ—μ„œ νˆ¬ν‘œν•˜λŠ” 일이 λ°œμƒν•˜μ—¬ ꡭ민의 뜻이 였히렀 μ™œκ³‘λ  수 μžˆλ‹€λ©° 우렀의 λͺ©μ†Œλ¦¬λ₯Ό λ‚΄κ³  μžˆλ‹€.
27
  """
28
  st.write(user_text)
29
+
30
  with col2:
31
  user_input = st.text_input("λͺ¨λ₯΄λŠ” λ¬Έμž₯μ΄λ‚˜ 단어λ₯Ό μž…λ ₯ν•˜μ„Έμš”:", "")
32
 
 
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."},
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()