mlo0ollm commited on
Commit
cad9fb2
โ€ข
1 Parent(s): 3b3393b

edit UI for small device & refactor major func

Browse files
Files changed (3) hide show
  1. app.py +138 -164
  2. gpt_based_function.py +112 -0
  3. text_annotator.py +45 -0
app.py CHANGED
@@ -1,12 +1,38 @@
1
  from annotated_text import annotated_text
 
2
  import streamlit as st
3
  import openai
4
  import os
 
 
 
 
 
 
 
 
 
5
 
6
  # OpenAI API ์„ค์ • (ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ์ฝ์–ด์˜ด)
7
  openai.api_key = os.getenv("OPENAI_API_KEY") # ์‹ค์ œ ์ฝ”๋“œ์—์„œ ์ฃผ์„ ํ•ด์ œ
8
  st.set_page_config(layout="wide")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  ## ํฌ์ธํŠธ ๋ถ€๋ถ„ ์ถ”๊ฐ€
12
  if 'points' not in st.session_state:
@@ -37,148 +63,117 @@ def display_markdown_table():
37
  ##๊ธฐ๋Šฅ์„ ํ•จ์ˆ˜๋กœ ๋‚˜๋ˆ„์–ด์„œ ๊ตฌํ˜„
38
  col, _ = st.columns(2)
39
 
40
- def display_passage(col):
41
- st.header("์ง€๋ฌธ")
42
  global text_container
43
  text_container = st.container() # ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
44
  # ๋ฏธ๋ฆฌ ๊ณต๊ฐ„ ํ™•๋ณด
45
  global text_placeholder
46
  text_placeholder = text_container.empty()
47
- global user_text
48
- user_text = """๋ฏผ์ฃผ์ฃผ์˜ ์‚ฌํšŒ๋Š” ๊ตญ๋ฏผ์ด ์ •์น˜์— ์ฐธ์—ฌํ•  ๊ถŒ๋ฆฌ๋ฅผ ๋ณด์žฅํ•œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ๊ถŒ๋ฆฌ๋ฅผ ์ฐธ์ •๊ถŒ์ด๋ผ ํ•˜๋Š”๋ฐ, ์ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ โ€˜์„ ๊ฑฐโ€™๋กœ ์‹คํ˜„๋œ๋‹ค. ์„ ๊ฑฐ๋Š” ์‚ฌํšŒ ์ง‘๋‹จ์˜ ๋Œ€ํ‘œ์ž๋‚˜ ๊ณต์ง์ž๋ฅผ ์„ ์ถœํ•˜์—ฌ ๊ทธ๋“ค์—๊ฒŒ ๋Œ€ํ‘œ์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ํ–‰์œ„์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋†’์€ ํˆฌํ‘œ์œจ์€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์ •๋‹น์„ฑ ํ™•๋ณด์™€ ๊นŠ์€ ๊ด€๋ จ์ด ์žˆ๋‹ค.<br><br>
49
- ์„ ๊ฑฐ ํˆฌํ‘œ ์ œ๋„์—๋Š” ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ํˆฌํ‘œ์ž์˜ ์ž์œ ์˜์‚ฌ์— ๋งก๊ธฐ๋Š” โ€˜์ž์œ  ํˆฌํ‘œ์ œโ€™์™€ ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ๊ตญ๋ฏผ์˜ ์˜๋ฌด๋กœ ๊ฐ„์ฃผํ•˜๊ณ  ์ •๋‹นํ•œ ์‚ฌ์œ  ์—†์ด ๊ธฐ๊ถŒํ•˜๋ฉด ๋ฒ•์  ์ œ์žฌ๋ฅผ ๊ฐ€ํ•˜๋Š” โ€˜์˜๋ฌด ํˆฌํ‘œ์ œโ€™๊ฐ€ ์žˆ๋‹ค. ์šฐ๋ฆฌ๋‚˜๋ผ๋Š” ์ž์œ  ํˆฌํ‘œ์ œ๋ฅผ ์ฑ„ํƒํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ตœ๊ทผ ์น˜๋ฅธ ์„ ๊ฑฐ์˜ ํ‰๊ท  ํˆฌํ‘œ์œจ์ด 50ํผ์„ผํŠธ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ฌ๋‹ค. ๊ฒฝ์ œ ๊ฐœ๋ฐœ ํ˜‘๋ ฅ ๊ธฐ๊ตฌ(OECD) ํšŒ์›๊ตญ ํ‰๊ท ์ด 70ํผ์„ผํŠธ๋Œ€์ธ ๊ฒƒ์„ ์ƒ๊ฐํ•˜๋ฉด ๋งค์šฐ ๋‚ฎ์€ ์ˆ˜์น˜๋ผ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ƒ๏ฟฝ๏ฟฝ๏ฟฝ์ด ์ง€์†๋˜์ž ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ์ด ์ œ์‹œ๋˜์—ˆ๊ณ , ์ž์œ  ํˆฌํ‘œ์ œ๊ฐ€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์›์น™์— ๋งž์œผ๋ฏ€๋กœ ์ด๋ฅผ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ๊ณผ ๋Œ€๋ฆฝํ•˜๊ณ  ์žˆ๋‹ค.<br><br>
50
- ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜์ž๋Š” ์ธก์€ ๋‚ฎ์€ ํˆฌํ‘œ์œจ๋กœ ํˆฌํ‘œ ๊ฒฐ๊ณผ์˜ ์ •๋‹น์„ฑ์„ ํ™•๋ณดํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋งค์šฐ ์‹ฌ๊ฐํ•˜๋‹ค๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๊ฐ•์ œ์„ฑ๊ณผ ๋ฒ•์  ์ œ์žฌ๊ฐ€ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋ฏ€๋กœ ํˆฌํ‘œ์œจ์ด ๋‚ฎ์•„์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ณธ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ตญ๋ฏผ ๋Œ€๋ถ€๋ถ„์ด ํˆฌํ‘œ์— ์ฐธ์—ฌํ•˜๊ฒŒ ๋˜๋ฉด ์ •์น˜์ธ๋“ค์ด ๋ชจ๋“  ๊ณ„์ธต์˜ ์ง€์ง€๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด ์ •์ฑ… ๊ฒฝ์Ÿ๋ ฅ์„ ๋†’์ด๋ ค ํ•  ๊ฒƒ์ด๋ฏ€๋กœ ์ •์น˜ ์†Œ์™ธ ๊ณ„์ธต์— ๋”์šฑ ๊ด€์‹ฌ์„ ์Ÿ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค.<br><br>
51
- ๋ฐ˜๋ฉด ์˜๋ฌด ํˆฌํ‘œ์ œ์— ๋ฐ˜๋Œ€ํ•˜๋Š” ์ธก์€ ํ˜„์žฌ ์šฐ๋ฆฌ๋‚˜๋ผ์˜ ํˆฌํ‘œ์œจ์ด ์ •์น˜ ์ง€๋„์ž๋“ค์˜ ๋Œ€ํ‘œ์„ฑ์„ ํ›ผ์†ํ•  ๋งŒํผ ์‹ฌ๊ฐํ•œ ์ƒํ™ฉ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋Š” ๊ฒƒ๋ณด๋‹ค ๊ตญ๋ฏผ์˜ ์‹ ๋ขฐ๋ฅผ ํšŒ๋ณตํ•˜๋Š” ๊ฒƒ์ด ๋” ์ค‘์š”ํ•˜๊ณ , ์‹œ๋ฏผ ๊ต์œก์ด๋‚˜ ๋ชจ์˜ ํˆฌํ‘œ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ๋„ ํˆฌํ‘œ์œจ ์ƒ์Šน์„ ๊ธฐ๋Œ€ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๋„์ž…๋งŒ์ด ํˆฌํ‘œ์œจ์ด๋‚˜ ์ •์น˜์  ๊ด€์‹ฌ์„ ๋†’์ด๋Š” ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜๋ฉด, ์„ ์ถœ๋œ ์ •์น˜์ธ๋“ค์ด ๋†’์€ ํˆฌํ‘œ์œจ์„ ํ•‘๊ณ„๋กœ ์•ˆํ•˜๋ฌด์ธ์˜ ํƒœ๋„๋ฅผ ๊ฐ–๋Š” ๋ถ€์ž‘์šฉ์ด ์ƒ๊ธด๋‹ค๋“ ๊ฐ€ ํ›„๋ณด์ž๋ฅผ ์ž˜ ๋ชจ๋ฅด๋Š” ์ƒํƒœ์—์„œ ํˆฌํ‘œํ•˜๋Š” ์ผ์ด ๋ฐœ์ƒํ•˜์—ฌ ๊ตญ๋ฏผ์˜ ๋œป์ด ์˜คํžˆ๋ ค ์™œ๊ณก๋  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์šฐ๋ ค์˜ ๋ชฉ์†Œ๋ฆฌ๋ฅผ ๋‚ด๊ณ  ์žˆ๋‹ค.<br><br>
52
- """
53
  text_placeholder.write(user_text, unsafe_allow_html=True)
54
  #์„ ์–ธํ•œ ๋ณ€์ˆ˜ ๋‹ค๋ฅธ ํ•จ์ˆ˜์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด return
55
  return text_placeholder, text_container, user_text
56
 
 
 
57
 
58
- def display_summary(col):
59
- st.header("์š”์•ฝ ๊ฒฐ๊ณผ")
60
- global user_summary
61
- user_summary = st.text_area("์š”์•ฝ๊ฒฐ๊ณผ๋ฅผ ์ œ์ถœํ•˜์„ธ์š”.")
62
-
63
  cols = st.columns(2)
64
  with cols[0]:
65
- btn_submit = st.button("์ œ์ถœ")
66
- if btn_submit:
67
- #๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ api ์ด์šฉํ•˜์—ฌ ์—…๋กœ๋“œ
68
- st.write("์ œ์ถœ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
69
- pass
70
 
71
- with cols[1]:
72
- btn_score = st.button("์ฑ„์ ํ•˜๊ธฐ")
73
- if btn_score and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
74
- update_points(1) # ํฌ์ธํŠธ ์ฆ๊ฐ€
75
- st.session_state.history.append(["์ฑ„์ ํ•˜๊ธฐ", -1, st.session_state.points])
76
- #๋ฃจ๋ธŒ๋ฆญ์— ์˜ํ•œ ์ฑ„์ 
77
- lubric = """์ฑ„์  ๊ธฐ์ค€ ์ƒ: ๋ฌธ์žฅ์˜ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•˜๊ณ , ์ฃผ์š” ๋‚ด์šฉ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ค‘: ๋ฌธ์žฅ์˜ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜: ๋ฌธ์žฅ์˜ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์—†๋‹ค."""
78
- #๋ฃจ๋ธŒ๋ฆญ ๊ธฐ์ค€์„ ์ด์šฉํ•ด์„œ ์ž…๋ ฅ์นธ์— ์ž…๋ ฅํ•œ ๋‚ด์šฉ์„ ์ฑ„์ ํ•˜๋Š” ์˜์–ด๋กœ ํ”„๋กฌํ”„ํŠธ
79
- explanation_task = f"{lubric}์„ ๊ธฐ์ค€์œผ๋กœ {user_summary}์˜ ๋‚ด์šฉ์„ ์ฑ„์ ํ•ด์ฃผ์„ธ์š”. ์ฑ„์  ๊ธฐ์ค€์€ ๊ณต๊ฐœํ•˜์ง€ ๋ง๊ณ  ์ƒ, ์ค‘,ํ•˜๋กœ ๋‚˜๋ˆ„๊ณ  ๊ฐ„๋‹จํ•œ ์ด์œ ๋ฅผ ์•Œ๋ ค์ฃผ์„ธ์š”."
80
- messages = [
81
- {"role": "system", "content": "You are a helpful assistant. use only korean"},
82
- {"role": "user", "content": explanation_task}
83
- ]
84
-
85
- response = openai.ChatCompletion.create(
86
- model="gpt-3.5-turbo-16k",
87
- messages=messages,
88
- temperature=0.1,
89
- max_tokens=2500
90
- )
91
-
92
- explanation = response['choices'][0]['message']['content']
93
- st.write(f"์ฑ„์  ํ•˜๊ธฐ: {explanation}")
94
- pass
95
  else:
96
  if st.session_state.points == 0:
97
  #ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์—†๋‹ค๋Š” ๋ฌธ๊ตฌ ์ถ”๊ฐ€
98
- st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์ฑ„์ ํ•˜๊ธฐ๋ฅผ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
99
  pass
100
 
101
- def display_input_btns(col):
102
- st.header("๏ฟฝ๏ฟฝ๊ณต์ง€๋Šฅ ์‚ฌ์šฉํ•˜๊ธฐ")
103
- global user_input
104
- user_input = st.text_area("๋‚ด์šฉ์„ ๋„ฃ๊ณ  ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”:", "์ถ”๊ฐ€ ์„ค๋ช…์ด ํ•„์š”ํ•˜๊ฑฐ๋‚˜ ๋‹ค์‹œ ์“ฐ๊ณ  ์‹ถ์€ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.")
105
-
106
- # ๋ฒ„ํŠผ row
107
- cols = st.columns(4)
108
- with cols[0]:
109
- btn_keyword = st.button("ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ")
110
- if btn_keyword and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
111
  update_points(-1) # ํฌ์ธํŠธ ๊ฐ์†Œ
112
- st.session_state.history.append(["ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ", -1, st.session_state.points])
113
- #๋‹ค๋ฅธ ์ง€๋ฌธ ๋„ฃ๊ธฐ
114
- highlighted_text = """**๋ฏผ์ฃผ์ฃผ์˜ ์‚ฌํšŒ**๋Š” ๊ตญ๋ฏผ์ด ์ •์น˜์— ์ฐธ์—ฌํ•  ๊ถŒ๋ฆฌ๋ฅผ ๋ณด์žฅํ•œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ๊ถŒ๋ฆฌ๋ฅผ **์ฐธ์ •๊ถŒ**์ด๋ผ ํ•˜๋Š”๋ฐ, ์ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ โ€˜์„ ๊ฑฐโ€™๋กœ ์‹คํ˜„๋œ๋‹ค. ์„ ๊ฑฐ๋Š” ์‚ฌํšŒ ์ง‘๋‹จ์˜ ๋Œ€ํ‘œ์ž๋‚˜ ๊ณต์ง์ž๋ฅผ ์„ ์ถœํ•˜์—ฌ ๊ทธ๋“ค์—๊ฒŒ ๋Œ€ํ‘œ์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ํ–‰์œ„์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ **๋†’์€ ํˆฌํ‘œ์œจ**์€ ๋ฏผ์ฃผ์ฃผ์˜์˜ **์ •๋‹น์„ฑ ํ™•๋ณด**์™€ ๊นŠ์€ ๊ด€๋ จ์ด ์žˆ๋‹ค.
115
 
116
- **์„ ๊ฑฐ ํˆฌํ‘œ ์ œ๋„**์—๋Š” ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ํˆฌํ‘œ์ž์˜ ์ž์œ ์˜์‚ฌ์— ๋งก๊ธฐ๋Š” โ€˜**์ž์œ  ํˆฌํ‘œ์ œ**โ€™์™€ ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ๊ตญ๋ฏผ์˜ ์˜๋ฌด๋กœ ๊ฐ„์ฃผํ•˜๊ณ  ์ •๋‹นํ•œ ์‚ฌ์œ  ์—†์ด ๊ธฐ๊ถŒํ•˜๋ฉด ๋ฒ•์  ์ œ์žฌ๋ฅผ ๊ฐ€ํ•˜๋Š” โ€˜**์˜๋ฌด ํˆฌํ‘œ์ œ**โ€™๊ฐ€ ์žˆ๋‹ค. ์šฐ๋ฆฌ๋‚˜๋ผ๋Š” ์ž์œ  ํˆฌํ‘œ์ œ๋ฅผ ์ฑ„ํƒํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ตœ๊ทผ ์น˜๋ฅธ ์„ ๊ฑฐ์˜ ํ‰๊ท  ํˆฌํ‘œ์œจ์ด 50ํผ์„ผํŠธ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ฌ๋‹ค. ๊ฒฝ์ œ ๊ฐœ๋ฐœ ํ˜‘๋ ฅ ๊ธฐ๊ตฌ(**OECD**) ํšŒ์›๊ตญ ํ‰๊ท ์ด 70ํผ์„ผํŠธ๋Œ€์ธ ๊ฒƒ์„ ์ƒ๊ฐํ•˜๋ฉด ๋งค์šฐ ๋‚ฎ์€ ์ˆ˜์น˜๋ผ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์ด ์ง€์†๋˜์ž ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ์ด ์ œ์‹œ๋˜์—ˆ๊ณ , ์ž์œ  ํˆฌํ‘œ์ œ๊ฐ€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์›์น™์— ๋งž์œผ๋ฏ€๋กœ ์ด๋ฅผ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ๊ณผ ๋Œ€๋ฆฝํ•˜๊ณ  ์žˆ๋‹ค.
117
 
118
- **์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜์ž๋Š” ์ธก**์€ ๋‚ฎ์€ ํˆฌํ‘œ์œจ๋กœ ํˆฌํ‘œ ๊ฒฐ๊ณผ์˜ **์ •๋‹น์„ฑ์„ ํ™•๋ณด**ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋งค์šฐ ์‹ฌ๊ฐํ•˜๋‹ค๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๊ฐ•์ œ์„ฑ๊ณผ ๋ฒ•์  ์ œ์žฌ๊ฐ€ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋ฏ€๋กœ ํˆฌํ‘œ์œจ์ด ๋‚ฎ์•„์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ณธ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ตญ๋ฏผ ๋Œ€๋ถ€๋ถ„์ด ํˆฌํ‘œ์— ์ฐธ์—ฌํ•˜๊ฒŒ ๋˜๋ฉด ์ •์น˜์ธ๋“ค์ด ๋ชจ๋“  ๊ณ„์ธต์˜ ์ง€์ง€๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด ์ •์ฑ… ๊ฒฝ์Ÿ๋ ฅ์„ ๋†’์ด๋ ค ํ•  ๊ฒƒ์ด๋ฏ€๋กœ **์ •์น˜ ์†Œ์™ธ ๊ณ„์ธต**์— ๋”์šฑ ๊ด€์‹ฌ์„ ์Ÿ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค.
 
 
 
119
 
120
- ๋ฐ˜๋ฉด **์˜๋ฌด ํˆฌํ‘œ์ œ์— ๋ฐ˜๋Œ€ํ•˜๋Š” ์ธก**์€ ํ˜„์žฌ ์šฐ๋ฆฌ๋‚˜๋ผ์˜ ํˆฌํ‘œ์œจ์ด ์ •์น˜ ์ง€๋„์ž๋“ค์˜ ๋Œ€ํ‘œ์„ฑ์„ ํ›ผ์†ํ•  ๋งŒํผ ์‹ฌ๊ฐํ•œ ์ƒํ™ฉ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋Š” ๊ฒƒ๋ณด๋‹ค **๊ตญ๋ฏผ์˜ ์‹ ๋ขฐ๋ฅผ ํšŒ๋ณต**ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ค‘์š”ํ•˜๊ณ , ์‹œ๋ฏผ ๊ต์œก์ด๋‚˜ ๋ชจ์˜ ํˆฌํ‘œ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ๋„ ํˆฌํ‘œ์œจ ์ƒ์Šน์„ ๊ธฐ๋Œ€ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๋„์ž…๋งŒ์ด ํˆฌํ‘œ์œจ์ด๋‚˜ ์ •์น˜์  ๊ด€์‹ฌ์„ ๋†’์ด๋Š” ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜๋ฉด, ์„ ์ถœ๋œ ์ •์น˜์ธ๋“ค์ด ๋†’์€ ํˆฌํ‘œ์œจ์„ ํ•‘๊ณ„๋กœ **์•ˆํ•˜๋ฌด์ธ์˜ ํƒœ๋„**๋ฅผ ๊ฐ–๋Š” ๋ถ€์ž‘์šฉ์ด ์ƒ๊ธด๋‹ค๋“ ๊ฐ€ ํ›„๋ณด์ž๋ฅผ ์ž˜ ๋ชจ๋ฅด๋Š” ์ƒํƒœ์—์„œ ํˆฌํ‘œํ•˜๋Š” ์ผ์ด ๋ฐœ์ƒํ•˜์—ฌ **๊ตญ๋ฏผ์˜ ๋œป์ด ์˜คํžˆ๋ ค ์™œ๊ณก**๋  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์šฐ๋ ค์˜ ๋ชฉ์†Œ๋ฆฌ๋ฅผ ๋‚ด๊ณ  ์žˆ๋‹ค.
121
- """
122
- # highlighted_text = annotated_text(
123
- # ("๋ฏผ์ฃผ์ฃผ์˜ ์‚ฌํšŒ", ""), "๋Š” ๊ตญ๋ฏผ์ด ์ •์น˜์— ์ฐธ์—ฌํ•  ๊ถŒ๋ฆฌ๋ฅผ ๋ณด์žฅํ•œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ๊ถŒ๋ฆฌ๋ฅผ ", ("์ฐธ์ •๊ถŒ", ""), "์ด๋ผ ํ•˜๋Š”๋ฐ, ์ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ โ€˜์„ ๊ฑฐโ€™๋กœ ์‹คํ˜„๋œ๋‹ค. ์„ ๊ฑฐ๋Š” ์‚ฌํšŒ ์ง‘๋‹จ์˜ ๋Œ€ํ‘œ์ž๋‚˜ ๊ณต์ง์ž๋ฅผ ์„ ์ถœํ•˜์—ฌ ๊ทธ๋“ค์—๊ฒŒ ๋Œ€ํ‘œ์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ํ–‰์œ„์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ", ("๋†’์€ ํˆฌํ‘œ์œจ", ""), "์€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ", ("์ •๋‹น์„ฑ ํ™•๋ณด", ""), "์™€ ๊นŠ์€ ๊ด€๋ จ์ด ์žˆ๋‹ค.\n\n", ("์„ ๊ฑฐ ํˆฌํ‘œ ์ œ๋„", ""), "์—๋Š” ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ํˆฌํ‘œ์ž์˜ ์ž์œ ์˜์‚ฌ์— ๋งก๊ธฐ๋Š” โ€˜", ("์ž์œ  ํˆฌํ‘œ์ œ", ""), "โ€™์™€ ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ๊ตญ๋ฏผ์˜ ์˜๋ฌด๋กœ ๊ฐ„์ฃผํ•˜๊ณ  ์ •๋‹นํ•œ ์‚ฌ์œ  ์—†์ด ๊ธฐ๊ถŒํ•˜๋ฉด ๋ฒ•์  ์ œ์žฌ๋ฅผ ๊ฐ€ํ•˜๋Š” โ€˜", ("์˜๋ฌด ํˆฌํ‘œ์ œ", ""), "โ€™๊ฐ€ ์žˆ๋‹ค. ์šฐ๋ฆฌ๋‚˜๋ผ๋Š” ์ž์œ  ํˆฌํ‘œ์ œ๋ฅผ ์ฑ„ํƒํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ตœ๊ทผ ์น˜๋ฅธ ์„ ๊ฑฐ์˜ ํ‰๊ท  ํˆฌํ‘œ์œจ์ด 50ํผ์„ผํŠธ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ฌ๋‹ค. ๊ฒฝ์ œ ๊ฐœ๋ฐœ ํ˜‘๋ ฅ ๊ธฐ๊ตฌ(", ("OECD", ""), ") ํšŒ์›๊ตญ ํ‰๊ท ์ด 70ํผ์„ผํŠธ๋Œ€์ธ ๊ฒƒ์„ ์ƒ๊ฐํ•˜๋ฉด ๋งค์šฐ ๋‚ฎ์€ ์ˆ˜์น˜๋ผ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์ด ์ง€์†๋˜์ž ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ์ด ์ œ์‹œ๋˜์—ˆ๊ณ , ์ž์œ  ํˆฌํ‘œ์ œ๊ฐ€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์›์น™์— ๋งž์œผ๏ฟฝ๏ฟฝ๏ฟฝ๋กœ ์ด๋ฅผ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ๊ณผ ๋Œ€๋ฆฝํ•˜๊ณ  ์žˆ๋‹ค.\n\n", ("์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜์ž๋Š” ์ธก", ""), "์€ ๋‚ฎ์€ ํˆฌํ‘œ์œจ๋กœ ํˆฌํ‘œ ๊ฒฐ๊ณผ์˜ ", ("์ •๋‹น์„ฑ์„ ํ™•๋ณด", ""), "ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋งค์šฐ ์‹ฌ๊ฐํ•˜๋‹ค๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๊ฐ•์ œ์„ฑ๊ณผ ๋ฒ•์  ์ œ์žฌ๊ฐ€ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋ฏ€๋กœ ํˆฌํ‘œ์œจ์ด ๋‚ฎ์•„์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ณธ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ตญ๋ฏผ ๋Œ€๋ถ€๋ถ„์ด ํˆฌํ‘œ์— ์ฐธ์—ฌํ•˜๊ฒŒ ๋˜๋ฉด ์ •์น˜์ธ๋“ค์ด ๋ชจ๋“  ๊ณ„์ธต์˜ ์ง€์ง€๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด ์ •์ฑ… ๊ฒฝ์Ÿ๋ ฅ์„ ๋†’์ด๋ ค ํ•  ๊ฒƒ์ด๋ฏ€๋กœ ", ("์ •์น˜ ์†Œ์™ธ ๊ณ„์ธต", ""), "์— ๋”์šฑ ๊ด€์‹ฌ์„ ์Ÿ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค.\n\n๋ฐ˜๋ฉด ", ("์˜๋ฌด ํˆฌํ‘œ์ œ์— ๋ฐ˜๋Œ€ํ•˜๋Š” ์ธก", ""), "์€ ํ˜„์žฌ ์šฐ๋ฆฌ๋‚˜๋ผ์˜ ํˆฌํ‘œ์œจ์ด ์ •์น˜ ์ง€๋„์ž๋“ค์˜ ๋Œ€ํ‘œ์„ฑ์„ ํ›ผ์†ํ•  ๋งŒํผ ์‹ฌ๊ฐํ•œ ์ƒํ™ฉ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋Š” ๊ฒƒ๋ณด๋‹ค ", ("๊ตญ๋ฏผ์˜ ์‹ ๋ขฐ๋ฅผ ํšŒ๋ณต", ""), "ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ค‘์š”ํ•˜๊ณ , ์‹œ๋ฏผ ๊ต์œก์ด๋‚˜ ๋ชจ์˜ ํˆฌํ‘œ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ๋„ ํˆฌํ‘œ์œจ ์ƒ์Šน์„ ๊ธฐ๋Œ€ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๋„์ž…๋งŒ์ด ํˆฌํ‘œ์œจ์ด๋‚˜ ์ •์น˜์  ๊ด€์‹ฌ์„ ๋†’์ด๋Š” ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜๋ฉด, ์„ ์ถœ๋œ ์ •์น˜์ธ๋“ค์ด ๋†’์€ ํˆฌํ‘œ์œจ์„ ํ•‘๊ณ„๋กœ ", ("์•ˆํ•˜๋ฌด์ธ์˜ ํƒœ๋„", ""), "๋ฅผ ๊ฐ–๋Š” ๋ถ€์ž‘์šฉ์ด ์ƒ๊ธด๋‹ค๋“ ๊ฐ€ ํ›„๋ณด์ž๋ฅผ ์ž˜ ๋ชจ๋ฅด๋Š” ์ƒํƒœ์—์„œ ํˆฌํ‘œํ•˜๋Š” ์ผ์ด ๋ฐœ์ƒํ•˜์—ฌ ", ("๊ตญ๋ฏผ์˜ ๋œป์ด ์˜คํžˆ๋ ค ์™œ๊ณก", ""), "๋  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์šฐ๋ ค์˜ ๋ชฉ์†Œ๋ฆฌ๋ฅผ ๋‚ด๊ณ  ์žˆ๋‹ค."
124
- # )
125
-
126
- # ๊ธฐ์กด ์ง€๋ฌธ ์ง€์šฐ๊ธฐ
127
- text_placeholder.empty()
128
- #text_container์— highlight๋œ ํ…์ŠคํŠธ๋ฅผ ์ถœ๋ ฅ
129
- with text_container:
130
- st.markdown(highlighted_text, unsafe_allow_html=True)
 
 
 
 
 
131
  else:
132
  if st.session_state.points == 0:
133
- #ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์—†๋‹ค๋Š” ๋ฌธ๊ตฌ ์ถ”๊ฐ€
134
- st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ํ‚ค์›Œ๋“œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
135
  pass
136
 
137
- with cols[1]:
138
- global btn_explanation
139
- btn_explanation= st.button("์ถ”๊ฐ€ ์„ค๋ช…")
140
- if btn_explanation and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
141
- update_points(1) # ํฌ์ธํŠธ ์ฆ๊ฐ€
142
- st.session_state.history.append(["์ถ”๊ฐ€ ์„ค๋ช…", 1, st.session_state.points])
 
 
143
 
144
- with cols[2]:
145
- global btn_simple
146
- btn_simple = st.button("์‰ฌ์šด ํ‘œํ˜„")
147
- if btn_simple and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
148
- update_points(-1) # ํฌ์ธํŠธ ๊ฐ์†Œ
149
- st.session_state.history.append(["์‰ฌ์šด ํ‘œํ˜„", -1, st.session_state.points])
150
-
151
-
152
- with cols[3]:
153
- global btn_rewrite
154
- btn_rewrite = st.button("๋‹ค์‹œ ์“ฐ๊ธฐ")
155
- if btn_rewrite and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
156
- update_points(-1) # ํฌ์ธํŠธ ๊ฐ์†Œ
157
- st.session_state.history.append(["๋‹ค์‹œ ์“ฐ๊ธฐ", -1, st.session_state.points])
158
-
159
-
160
- return btn_keyword, btn_explanation, btn_simple, btn_rewrite
161
 
162
 
163
- def display_output():
164
  with st.container():
165
- st.header("๊ฒฐ๊ณผ")
 
 
 
 
 
 
 
 
 
 
166
  if btn_explanation and st.session_state.points > 0:
167
- explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {user_text}"
168
-
169
- messages = [
170
- {"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"},
171
- {"role": "user", "content": explanation_task}
172
- ]
173
-
174
- response = openai.ChatCompletion.create(
175
- model="gpt-3.5-turbo-16k",
176
- messages=messages,
177
- temperature=0.1,
178
- max_tokens=200
179
- )
180
-
181
- explanation = response['choices'][0]['message']['content']
182
 
183
  # ์ถ”๊ฐ€ ์„ค๋ช…
184
  st.write(f"์ถ”๊ฐ€ ์„ค๋ช…: {explanation}")
@@ -190,70 +185,49 @@ def display_output():
190
 
191
  pass
192
 
193
- if btn_simple and st.session_state.points > 0:
194
- explanation_task = f"Describe the fingerprint of '{user_text}' in a way that an elementary school student could understand."
195
-
196
- messages = [
197
- {"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"},
198
- {"role": "user", "content": explanation_task}
199
- ]
200
-
201
- response = openai.ChatCompletion.create(
202
- model="gpt-3.5-turbo-16k",
203
- messages=messages,
204
- temperature=0.1,
205
- max_tokens=2500
206
- )
207
-
208
- explanation = response['choices'][0]['message']['content']
209
-
210
- # ์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
211
- st.write(f"์‰ฌ์šด ๊ธ€: {explanation}")
212
  pass
213
  else:
214
  if st.session_state.points == 0:
215
- st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์‰ฌ์šด ํ‘œํ˜„ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
216
  pass
217
 
218
- if btn_rewrite and st.session_state.points > 0:
219
- explanation_task = f"Rewrite the contents of '{user_input}' so that it will pass the writing test."
220
-
221
- messages = [
222
- {"role": "system", "content": "You are a helpful assistant. use only korean"},
223
- {"role": "user", "content": explanation_task}
224
- ]
225
-
226
- response = openai.ChatCompletion.create(
227
- model="gpt-3.5-turbo-16k",
228
- messages=messages,
229
- temperature=0.1,
230
- max_tokens=2500
231
- )
232
-
233
- explanation = response['choices'][0]['message']['content']
234
-
235
- st.write(f"๋‹ค์‹œ ์“ฐ๊ธฐ: {explanation}")
236
- pass
237
- else:
238
- if st.session_state.points == 0:
239
- st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ๋‹ค์‹œ ์“ฐ๊ธฐ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
240
 
241
- pass
242
-
243
 
244
  def main():
245
- st.title("ํ•œ๊ตญ์–ด ํ•™์Šต์ž๋ฅผ ์œ„ํ•œ HCI tools")
246
  #ํฌ์ธํŠธ ์‹œ์Šคํ…œ ์„ค๋ช… ์ถ”๊ฐ€
247
- st.sidebar.markdown("ํฌ์ธํŠธ๋Š” 3์ ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ, **ํ‚ค์›Œ๋“œ ์ฐพ๊ธฐ**, **์‰ฌ์šด ํ‘œํ˜„**, **๋‹ค์‹œ ์“ฐ๊ธฐ**๋ฅผ ํ•  ๋•Œ 1์ ์”ฉ ๊ฐ์†Œํ•ฉ๋‹ˆ๋‹ค. **์ถ”๊ฐ€ ์„ค๋ช…**๊ณผ **์ฑ„์ ํ•˜๊ธฐ**๋ฅผ ํ•  ๋•Œ 1์ ์”ฉ ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ํฌ์ธํŠธ๊ฐ€ 0์ ์ด ๋˜๋ฉด ๋” ์ด์ƒ ์ž‘์—…์„ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ")
 
 
 
248
 
249
- col1, col2 = st.columns(2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
 
251
- with col1:
252
- display_passage(col1)
253
- display_summary(col1)
254
- with col2:
255
- btn_keyword, btn_explanation, btn_simple, btn_rewrite = display_input_btns(col2)
256
- display_output()
257
  #ํฌ์ธํŠธ ํ‘œ์‹œ
258
  display_points()
259
  #ํฌ์ธํŠธ ๋ณ€ํ™” ํ‘œ์‹œ
 
1
  from annotated_text import annotated_text
2
+ import ast
3
  import streamlit as st
4
  import openai
5
  import os
6
+ import sys
7
+ from gpt_based_function import gpt_keyword_highlighter, gpt_text_naturalizer, gpt_explanation_generator, gpt_easier_text_generator, gpt_rater
8
+ import concurrent.futures
9
+ from tqdm import tqdm
10
+
11
+
12
+ # current_path = '/Users/kintch/PycharmProjects/jungu_sgi/summary_with_gpt'
13
+ # os.chdir(current_path)
14
+ # sys.path.append(current_path)
15
 
16
  # OpenAI API ์„ค์ • (ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ์ฝ์–ด์˜ด)
17
  openai.api_key = os.getenv("OPENAI_API_KEY") # ์‹ค์ œ ์ฝ”๋“œ์—์„œ ์ฃผ์„ ํ•ด์ œ
18
  st.set_page_config(layout="wide")
19
 
20
+ user_text = """๋ฏผ์ฃผ์ฃผ์˜ ์‚ฌํšŒ๋Š” ๊ตญ๋ฏผ์ด ์ •์น˜์— ์ฐธ์—ฌํ•  ๊ถŒ๋ฆฌ๋ฅผ ๋ณด์žฅํ•œ๋‹ค. ๊ทธ๋Ÿฌํ•œ ๊ถŒ๋ฆฌ๋ฅผ ์ฐธ์ •๊ถŒ์ด๋ผ ํ•˜๋Š”๋ฐ, ์ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ โ€˜์„ ๊ฑฐโ€™๋กœ ์‹คํ˜„๋œ๋‹ค. ์„ ๊ฑฐ๋Š” ์‚ฌํšŒ ์ง‘๋‹จ์˜ ๋Œ€ํ‘œ์ž๋‚˜ ๊ณต์ง์ž๋ฅผ ์„ ์ถœํ•˜์—ฌ ๊ทธ๋“ค์—๊ฒŒ ๋Œ€ํ‘œ์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ํ–‰์œ„์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋†’์€ ํˆฌํ‘œ์œจ์€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์ •๋‹น์„ฑ ํ™•๋ณด์™€ ๊นŠ์€ ๊ด€๋ จ์ด ์žˆ๋‹ค.
21
+ ์„ ๊ฑฐ ํˆฌํ‘œ ์ œ๋„์—๋Š” ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ํˆฌํ‘œ์ž์˜ ์ž์œ ์˜์‚ฌ์— ๋งก๊ธฐ๋Š” โ€˜์ž์œ  ํˆฌํ‘œ์ œโ€™์™€ ํˆฌํ‘œ๊ถŒ ํ–‰์‚ฌ๋ฅผ ๊ตญ๋ฏผ์˜ ์˜๋ฌด๋กœ ๊ฐ„์ฃผํ•˜๊ณ  ์ •๋‹นํ•œ ์‚ฌ์œ  ์—†์ด ๊ธฐ๊ถŒํ•˜๋ฉด ๋ฒ•์  ์ œ์žฌ๋ฅผ ๊ฐ€ํ•˜๋Š” โ€˜์˜๋ฌด ํˆฌํ‘œ์ œโ€™๊ฐ€ ์žˆ๋‹ค. ์šฐ๋ฆฌ๋‚˜๋ผ๋Š” ์ž์œ  ํˆฌํ‘œ์ œ๋ฅผ ์ฑ„ํƒํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ตœ๊ทผ ์น˜๋ฅธ ์„ ๊ฑฐ์˜ ํ‰๊ท  ํˆฌํ‘œ์œจ์ด 50ํผ์„ผํŠธ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ฌ๋‹ค. ๊ฒฝ์ œ ๊ฐœ๋ฐœ ํ˜‘๋ ฅ ๊ธฐ๊ตฌ(OECD) ํšŒ์›๊ตญ ํ‰๊ท ์ด 70ํผ์„ผํŠธ๋Œ€์ธ ๊ฒƒ์„ ์ƒ๊ฐํ•˜๋ฉด ๋งค์šฐ ๋‚ฎ์€ ์ˆ˜์น˜๋ผ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์ด ์ง€์†๋˜์ž ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ์ด ์ œ์‹œ๋˜์—ˆ๊ณ , ์ž์œ  ํˆฌํ‘œ์ œ๊ฐ€ ๋ฏผ์ฃผ์ฃผ์˜์˜ ์›์น™์— ๋งž์œผ๋ฏ€๋กœ ์ด๋ฅผ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค๋Š” ์˜๊ฒฌ๊ณผ ๋Œ€๋ฆฝํ•˜๊ณ  ์žˆ๋‹ค.
22
+ ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜์ž๋Š” ์ธก์€ ๋‚ฎ์€ ํˆฌํ‘œ์œจ๋กœ ํˆฌํ‘œ ๊ฒฐ๊ณผ์˜ ์ •๋‹น์„ฑ์„ ํ™•๋ณดํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋งค์šฐ ์‹ฌ๊ฐํ•˜๋‹ค๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๊ฐ•์ œ์„ฑ๊ณผ ๋ฒ•์  ์ œ์žฌ๊ฐ€ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋ฏ€๋กœ ํˆฌํ‘œ์œจ์ด ๋‚ฎ์•„์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋ณธ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ตญ๋ฏผ ๋Œ€๋ถ€๋ถ„์ด ํˆฌํ‘œ์— ์ฐธ์—ฌํ•˜๊ฒŒ ๋˜๋ฉด ์ •์น˜์ธ๋“ค์ด ๋ชจ๋“  ๊ณ„์ธต์˜ ์ง€์ง€๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•ด ์ •์ฑ… ๊ฒฝ์Ÿ๋ ฅ์„ ๋†’์ด๋ ค ํ•  ๊ฒƒ์ด๋ฏ€๋กœ ์ •์น˜ ์†Œ์™ธ ๊ณ„์ธต์— ๋”์šฑ ๊ด€์‹ฌ์„ ์Ÿ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค.
23
+ ๋ฐ˜๋ฉด ์˜๋ฌด ํˆฌํ‘œ์ œ์— ๋ฐ˜๋Œ€ํ•˜๋Š” ์ธก์€ ํ˜„์žฌ ์šฐ๋ฆฌ๋‚˜๋ผ์˜ ํˆฌํ‘œ์œจ์ด ์ •์น˜ ์ง€๋„์ž๋“ค์˜ ๋Œ€ํ‘œ์„ฑ์„ ํ›ผ์†ํ•  ๋งŒํผ ์‹ฌ๊ฐํ•œ ์ƒํ™ฉ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ฃผ์žฅํ•œ๋‹ค. ๋˜ ํˆฌํ‘œ์œจ์„ ๋†’์ด๋Š” ๊ฒƒ๋ณด๋‹ค ๊ตญ๋ฏผ์˜ ์‹ ๋ขฐ๋ฅผ ํšŒ๋ณตํ•˜๋Š” ๊ฒƒ์ด ๋” ์ค‘์š”ํ•˜๊ณ , ์‹œ๋ฏผ ๊ต์œก์ด๋‚˜ ๋ชจ์˜ ํˆฌํ‘œ ๊ต์œก ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ๋„ ํˆฌํ‘œ์œจ ์ƒ์Šน์„ ๊ธฐ๋Œ€ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์˜๋ฌด ํˆฌํ‘œ์ œ์˜ ๋„์ž…๋งŒ์ด ํˆฌํ‘œ์œจ์ด๋‚˜ ์ •์น˜์  ๊ด€์‹ฌ์„ ๋†’์ด๋Š” ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์€ ์•„๋‹ˆ๋ผ๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์˜๋ฌด ํˆฌํ‘œ์ œ๋ฅผ ๋„์ž…ํ•˜๋ฉด, ์„ ์ถœ๋œ ์ •์น˜์ธ๋“ค์ด ๋†’์€ ํˆฌํ‘œ์œจ์„ ํ•‘๊ณ„๋กœ ์•ˆํ•˜๋ฌด์ธ์˜ ํƒœ๋„๋ฅผ ๊ฐ–๋Š” ๋ถ€์ž‘์šฉ์ด ์ƒ๊ธด๋‹ค๋“ ๊ฐ€ ํ›„๋ณด์ž๋ฅผ ์ž˜ ๋ชจ๋ฅด๋Š” ์ƒํƒœ์—์„œ ํˆฌํ‘œํ•˜๋Š” ์ผ์ด ๋ฐœ์ƒํ•˜์—ฌ ๊ตญ๋ฏผ์˜ ๋œป์ด ์˜คํžˆ๋ ค ์™œ๊ณก๋  ์ˆ˜ ์žˆ๋‹ค๋ฉฐ ์šฐ๋ ค์˜ ๋ชฉ์†Œ๋ฆฌ๋ฅผ ๋‚ด๊ณ  ์žˆ๋‹ค."""
24
+
25
+ user_text_paragraphs = user_text.split("\n") #๋ฌธ๋‹จ๋ณ„๋กœ ์ชผ๊ฐœ๊ธฐ
26
+
27
+ is_easier_button_pressed = [False]*len(user_text_paragraphs)
28
+
29
+ def run(list_sum):
30
+ with concurrent.futures.ThreadPoolExecutor() as executor:
31
+ results = list(tqdm(executor.map(gpt_keyword_highlighter, list_sum), total=len(list_sum)))
32
+ return results
33
+
34
+ # SHOUD BE ํ™œ์„ฑํ™”
35
+ highlighted_texts_list = run(user_text_paragraphs)
36
 
37
  ## ํฌ์ธํŠธ ๋ถ€๋ถ„ ์ถ”๊ฐ€
38
  if 'points' not in st.session_state:
 
63
  ##๊ธฐ๋Šฅ์„ ํ•จ์ˆ˜๋กœ ๋‚˜๋ˆ„์–ด์„œ ๊ตฌํ˜„
64
  col, _ = st.columns(2)
65
 
66
+ def display_passage(user_text):
67
+ # st.header("์ง€๋ฌธ")
68
  global text_container
69
  text_container = st.container() # ์ถ”๊ฐ€๋œ ์ฝ”๋“œ
70
  # ๋ฏธ๋ฆฌ ๊ณต๊ฐ„ ํ™•๋ณด
71
  global text_placeholder
72
  text_placeholder = text_container.empty()
 
 
 
 
 
 
73
  text_placeholder.write(user_text, unsafe_allow_html=True)
74
  #์„ ์–ธํ•œ ๋ณ€์ˆ˜ ๋‹ค๋ฅธ ํ•จ์ˆ˜์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด return
75
  return text_placeholder, text_container, user_text
76
 
77
+ def display_preset_func_btns(col):
78
+ # st.header("์ธ๊ณต์ง€๋Šฅ ์‚ฌ์šฉํ•˜๊ธฐ")
79
 
80
+ # ๋ฒ„ํŠผ row
 
 
 
 
81
  cols = st.columns(2)
82
  with cols[0]:
83
+ btn_gpt_keyword_func = st.button("ํ‚ค์›Œ๋“œ๋ฅผ ์ฐพ์•„์ค˜")
84
+ if btn_gpt_keyword_func and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
85
+ update_points(-1) # ํฌ์ธํŠธ ๊ฐ์†Œ
86
+ st.session_state.history.append(["ํ‚ค์›Œ๋“œ๋ฅผ ์ฐพ์•„์ค˜", -1, st.session_state.points])
 
87
 
88
+ global is_easier_button_pressed
89
+ is_easier_button_pressed = [True]*len(user_text_paragraphs)
90
+
91
+ # ๋‹ค๋ฅธ ๋กœ์ง ๊ณ ๋ ค
92
+ #๋‹ค๋ฅธ ์ง€๋ฌธ ๋„ฃ๊ธฐ
93
+ # global highlighted_texts_list
94
+ # highlighted_text = highlighted_texts_list[-1]
95
+ #
96
+ # # ๊ธฐ์กด ์ง€๋ฌธ ์ง€์šฐ๊ธฐ
97
+ # text_placeholder.empty()
98
+ #
99
+ # #text_container์— highlight๋œ ํ…์ŠคํŠธ๋ฅผ ์ถœ๋ ฅ
100
+ # with text_container:
101
+ # exec(highlighted_text)
102
+ # st.markdown(highlighted_text, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
103
  else:
104
  if st.session_state.points == 0:
105
  #ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์—†๋‹ค๋Š” ๋ฌธ๊ตฌ ์ถ”๊ฐ€
106
+ st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ํ‚ค์›Œ๋“œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
107
  pass
108
 
109
+ with cols[1]:
110
+ global btn_gpt_easier_text_func
111
+ btn_gpt_easier_text_func = st.button("์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๋ฐ”๊ฟ”์ค˜")
112
+ if btn_gpt_easier_text_func and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
 
 
 
 
 
 
113
  update_points(-1) # ํฌ์ธํŠธ ๊ฐ์†Œ
114
+ st.session_state.history.append(["์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๋ฐ”๊ฟ”์ค˜", -1, st.session_state.points])
115
+
 
116
 
117
+ # return btn_gpt_keyword_func, btn_gpt_easier_text_func
118
 
119
+ def display_users_summarization(col):
120
+ # st.header("์š”์•ฝ ๊ฒฐ๊ณผ")
121
+ global user_summary
122
+ user_summary = st.text_area("ํ•œ ๋ฌธ๋‹จ์”ฉ ์ฝ๊ณ  ์ „์ฒด ๊ธ€์„ ์š”์•ฝํ•ด๋ณด์„ธ์š”.", key='user_summary')
123
 
124
+ cols = st.columns(2)
125
+ with cols[0]:
126
+ global btn_gpt_naturalize_func
127
+ btn_gpt_naturalize_func = st.button("๊ธ€ ๋‹ค๋“ฌ๊ธฐ")
128
+ if btn_gpt_naturalize_func and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
129
+ update_points(-1) # ํฌ์ธํŠธ ๊ฐ์†Œ
130
+ st.session_state.history.append(["๊ธ€ ๋‹ค๋“ฌ๊ธฐ", -1, st.session_state.points])
131
+ with cols[1]:
132
+ btn_gpt_rating_func = st.button("์ฑ„์ ํ•˜๊ธฐ")
133
+ if btn_gpt_rating_func and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
134
+ update_points(1) # ํฌ์ธํŠธ ์ฆ๊ฐ€
135
+ st.session_state.history.append(["์ฑ„์ ํ•˜๊ธฐ", +1, st.session_state.points]) #fix from -1 to +1
136
+ gpt_rated_result = gpt_rater(user_summary)
137
+ st.write(f"์ฑ„์ ํ•˜๊ธฐ: {gpt_rated_result}")
138
+ # https://discuss.streamlit.io/t/streamlit-button-disable-enable/31293 # ๋ฒ„ํŠผ ๋น„ํ™œ์„ฑํ™” ๊ด€๋ จ ์ฐธ๊ณ  (์•„์ง์€ ์•ˆ๋จ)
139
+ pass
140
  else:
141
  if st.session_state.points == 0:
142
+ # ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์—†๋‹ค๋Š” ๋ฌธ๊ตฌ ์ถ”๊ฐ€
143
+ st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์ฑ„์ ํ•˜๊ธฐ๋ฅผ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
144
  pass
145
 
146
+ if btn_gpt_naturalize_func and st.session_state.points > 0:
147
+ naturalized_text = gpt_text_naturalizer(user_summary) # ๋‹ค์‹œ์“ฐ๊ธฐ ํ•จ์ˆ˜
148
+ st.write(f"๊ธ€ ๋‹ค๋“ฌ๊ธฐ: {naturalized_text}")
149
+ pass
150
+ else:
151
+ if st.session_state.points == 0:
152
+ st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ๊ธ€ ๋‹ค๋“ฌ๊ธฐ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
153
+ pass
154
 
155
+ btn_submit_summarized_text = st.button("์ œ์ถœํ•˜๊ธฐ")
156
+ if btn_submit_summarized_text:
157
+ # ๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ api ์ด์šฉํ•˜์—ฌ ์—…๋กœ๋“œ
158
+ st.write("์ œ์ถœ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
159
+ pass
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
 
162
+ def display_qna_with_gpt():
163
  with st.container():
164
+ cols = st.columns(2)
165
+ # st.header("๊ฒฐ๊ณผ")
166
+ with cols[0]:
167
+ global btn_explanation
168
+ btn_explanation = st.button("์ถ”๊ฐ€ ์„ค๋ช…")
169
+ if btn_explanation and st.session_state.points > 0: # ํฌ์ธํŠธ ์ฒดํฌ
170
+ update_points(1) # ํฌ์ธํŠธ ์ฆ๊ฐ€
171
+ st.session_state.history.append(["์ถ”๊ฐ€ ์„ค๋ช…", 1, st.session_state.points])
172
+
173
+ user_input = st.text_area("์ถ”๊ฐ€ ์„ค๋ช…์ด ํ•„์š”ํ•˜๊ฑฐ๋‚˜ ๋‹ค์‹œ ์“ฐ๊ณ  ์‹ถ์€ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”.", key='user_input')
174
+
175
  if btn_explanation and st.session_state.points > 0:
176
+ explanation = gpt_explanation_generator(user_input, user_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
  # ์ถ”๊ฐ€ ์„ค๋ช…
179
  st.write(f"์ถ”๊ฐ€ ์„ค๋ช…: {explanation}")
 
185
 
186
  pass
187
 
188
+ if btn_gpt_easier_text_func and st.session_state.points > 0:
189
+ easier_text = gpt_easier_text_generator(user_input)
190
+
191
+ # ์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๋ฐ”๊ฟ”์ค˜์œผ๋กœ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
192
+ st.write(f"์‰ฌ์šด ๊ธ€: {easier_text}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  pass
194
  else:
195
  if st.session_state.points == 0:
196
+ st.write("ํฌ์ธํŠธ๊ฐ€ ์—†์–ด์„œ ์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๋ฐ”๊ฟ”์ค˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
197
  pass
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
 
 
200
 
201
  def main():
202
+ st.title("์ฑ—GPT์™€ ํ•จ๊ป˜ ์š”์•ฝํ•˜๊ธฐ")
203
  #ํฌ์ธํŠธ ์‹œ์Šคํ…œ ์„ค๋ช… ์ถ”๊ฐ€
204
+ st.sidebar.markdown("ํฌ์ธํŠธ๋Š” 3์ ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ, **ํ‚ค์›Œ๋“œ๋ฅผ ์ฐพ์•„์ค˜**, **์‰ฌ์šด ํ‘œํ˜„์œผ๋กœ ๋ฐ”๊ฟ”์ค˜**, **๊ธ€ ๋‹ค๋“ฌ๊ธฐ**๋ฅผ ํ•  ๋•Œ 1์ ์”ฉ ๊ฐ์†Œํ•ฉ๋‹ˆ๋‹ค. **์ถ”๊ฐ€ ์„ค๋ช…**๊ณผ **์ฑ„์ ํ•˜๊ธฐ**๋ฅผ ํ•  ๋•Œ 1์ ์”ฉ ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ํฌ์ธํŠธ๊ฐ€ 0์ ์ด ๋˜๋ฉด ๋” ์ด์ƒ ์ž‘์—…์„ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ")
205
+
206
+ # col1, col2 = st.columns(2)
207
+ display_preset_func_btns(col)
208
 
209
+ # Paragraph Tabs
210
+ paragraph_tab1, paragraph_tab2, paragraph_tab3, paragraph_tab4 = st.tabs(["๋‹จ๋ฝ1", "๋‹จ๋ฝ2", "๋‹จ๋ฝ3", "๋‹จ๋ฝ4"])
211
+ with paragraph_tab1:
212
+ if is_easier_button_pressed[0]:
213
+ text = ast.literal_eval(highlighted_texts_list[0][15:-1])
214
+ annotated_text(*text) #exec ๋Œ€์‹  ์ธ์ž๋กœ ๋ฐ”๋กœ ์ „๋‹ฌ
215
+ else:
216
+ display_passage(user_text_paragraphs[0])
217
+ with paragraph_tab2:
218
+ display_passage(user_text_paragraphs[1])
219
+ with paragraph_tab3:
220
+ display_passage(user_text_paragraphs[2])
221
+ with paragraph_tab4:
222
+ display_passage(user_text_paragraphs[3])
223
+
224
+ # User Input Tabs
225
+ user_input_tab1, user_input_tab2 = st.tabs(["์š”์•ฝํ•˜๊ธฐ", "์ฑ—GPT์—๊ฒŒ ์งˆ๋ฌธํ•˜๊ธฐ"])
226
+ with user_input_tab1:
227
+ display_users_summarization(col)
228
+ with user_input_tab2:
229
+ display_qna_with_gpt()
230
 
 
 
 
 
 
 
231
  #ํฌ์ธํŠธ ํ‘œ์‹œ
232
  display_points()
233
  #ํฌ์ธํŠธ ๋ณ€ํ™” ํ‘œ์‹œ
gpt_based_function.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ast
2
+ import openai
3
+ from text_annotator import generate_annotated_text
4
+
5
+
6
+ def gpt_keyword_highlighter(user_text):
7
+ '''
8
+ :param user_text: str
9
+ :return: annotated_text: str
10
+ '''
11
+ task_description = "You are a Python function that extract 5 keywords from {input_text}. The output should be formatted as ['keyword1', 'keyword2', ...]. Return only the function's output, with no additional explanations."
12
+
13
+ user_prompt = r"{input_text}=" + f"{user_text}"
14
+
15
+ messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
16
+
17
+ response = openai.ChatCompletion.create(
18
+ model="gpt-3.5-turbo",
19
+ messages=messages,
20
+ temperature=0,
21
+ max_tokens=1019,
22
+ top_p=0,
23
+ frequency_penalty=0,
24
+ presence_penalty=0
25
+ )
26
+
27
+ extracted_keywords = response['choices'][0]['message']['content']
28
+
29
+ ## literal_eval ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ string์„ list๋กœ ๋ณ€ํ™˜
30
+ extracted_keywords = ast.literal_eval(extracted_keywords)
31
+
32
+ ## highlighted_text ํ›„์ฒ˜๋ฆฌ ํ•จ์ˆ˜ ์ถ”๊ฐ€
33
+ highlighted_text = generate_annotated_text(text=user_text, keyw_list=extracted_keywords)
34
+
35
+ return highlighted_text
36
+
37
+
38
+ def gpt_text_naturalizer(user_input):
39
+ paraphrasing_task = f"Rewrite the contents of '{user_input}' so that it will pass the writing test."
40
+
41
+ messages = [
42
+ {"role": "system", "content": "You are a helpful assistant. use only korean"},
43
+ {"role": "user", "content": paraphrasing_task}
44
+ ]
45
+
46
+ response = openai.ChatCompletion.create(
47
+ model="gpt-3.5-turbo-16k",
48
+ messages=messages,
49
+ temperature=0.1,
50
+ max_tokens=2500
51
+ )
52
+
53
+ paraphrased_text = response['choices'][0]['message']['content']
54
+ return paraphrased_text
55
+
56
+
57
+ def gpt_explanation_generator(user_input, text_to_consider):
58
+ explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {text_to_consider}"
59
+
60
+ messages = [
61
+ {"role": "system",
62
+ "content": "You are a helpful assistant that explains complex topics in a way that an elementary school student can understand. use only korean"},
63
+ {"role": "user", "content": explanation_task}
64
+ ]
65
+
66
+ response = openai.ChatCompletion.create(
67
+ model="gpt-3.5-turbo-16k",
68
+ messages=messages,
69
+ temperature=0.1,
70
+ max_tokens=200
71
+ )
72
+
73
+ explanation = response['choices'][0]['message']['content']
74
+ return explanation
75
+
76
+
77
+ def gpt_easier_text_generator(user_input):
78
+ messages = [
79
+ {"role": "system",
80
+ "content": "You have a special talent for easily rewriting text. Make it easy to paraphrase, use simple words that an elementary school student can understand, but don't shorten or summarize. Don't forget to use only korean."},
81
+ {"role": "user", "content": user_input}
82
+ ]
83
+
84
+ response = openai.ChatCompletion.create(
85
+ model="gpt-3.5-turbo",
86
+ messages=messages,
87
+ temperature=0,
88
+ max_tokens=2048
89
+ )
90
+
91
+ explanation = response['choices'][0]['message']['content']
92
+
93
+
94
+ def gpt_rater(user_input):
95
+ # ๋ฃจ๋ธŒ๋ฆญ์— ์˜ํ•œ ์ฑ„์ 
96
+ lubric = """์ฑ„์  ๊ธฐ์ค€ ์ƒ: ๋ฌธ์žฅ์˜ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•˜๊ณ , ์ฃผ์š” ๋‚ด์šฉ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ค‘: ๋ฌธ์žฅ์˜ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜: ๋ฌธ์žฅ์˜ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์—†๋‹ค."""
97
+ # ๋ฃจ๋ธŒ๋ฆญ ๊ธฐ์ค€์„ ์ด์šฉํ•ด์„œ ์ž…๋ ฅ์นธ์— ์ž…๋ ฅํ•œ ๋‚ด์šฉ์„ ์ฑ„์ ํ•˜๋Š” ์˜์–ด๋กœ ํ”„๋กฌํ”„ํŠธ
98
+ explanation_task = f"{lubric}์„ ๊ธฐ์ค€์œผ๋กœ {user_input}์˜ ๋‚ด์šฉ์„ ์ฑ„์ ํ•ด์ฃผ์„ธ์š”. ์ฑ„์  ๊ธฐ์ค€์€ ๊ณต๊ฐœํ•˜์ง€ ๋ง๊ณ  ์ƒ, ์ค‘,ํ•˜๋กœ ๋‚˜๋ˆ„๊ณ  ๊ฐ„๋‹จํ•œ ์ด์œ ๋ฅผ ์•Œ๋ ค์ฃผ์„ธ์š”."
99
+ messages = [
100
+ {"role": "system", "content": "You are a helpful assistant. use only korean"},
101
+ {"role": "user", "content": explanation_task}
102
+ ]
103
+
104
+ response = openai.ChatCompletion.create(
105
+ model="gpt-3.5-turbo-16k",
106
+ messages=messages,
107
+ temperature=0.1,
108
+ max_tokens=2500
109
+ )
110
+
111
+ feedback = response['choices'][0]['message']['content']
112
+ return feedback
text_annotator.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ def generate_annotated_text(text, keyw_list):
4
+ '''
5
+ :param text: str
6
+ :param keyw_list: list of str
7
+ :return: str
8
+
9
+ e.g. input1 = 'I like an apple. Do you like apples too?'
10
+ input2 = ["like", "apple"]
11
+ output = annotated_text("I ", ("like", ""), " an ", ("apple", ""), ". Do you ", ("like", ""), " ", ("apple", ""), "s too?")
12
+ '''
13
+ def find_keyword_index(text, keyw_list):
14
+ indices = []
15
+
16
+ for keyword in keyw_list:
17
+ for match in re.finditer(keyword, text):
18
+ indices.append((keyword, match.start()))
19
+
20
+ return indices
21
+
22
+ indices = find_keyword_index(text, keyw_list)
23
+
24
+ # 1. indices๋ฅผ index ๊ฐ’์— ๋”ฐ๋ผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ
25
+ sorted_indices = sorted(indices, key=lambda x: x[1])
26
+
27
+ output = 'annotated_text('
28
+ last_index = 0
29
+
30
+ # 2. input1์—์„œ ๊ฐ ํ‚ค์›Œ๋“œ์˜ ์œ„์น˜๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด ๋ถ„ํ•  ๋ฐ ์žฌ์ฒ˜๋ฆฌ
31
+ for word, start_idx in sorted_indices:
32
+ output += f'"{text[last_index:start_idx]}", ("{word}", ""), '
33
+ last_index = start_idx + len(word)
34
+
35
+ # 3. ๊ฒฐ๊ณผ ๋ฌธ์ž์—ด ์ƒ์„ฑ
36
+ output += f'"{text[last_index:]}"' + ')'
37
+
38
+ # 4. ์—ฐ์† ๋ฌธ์ž์—ด ๋Œ€์น˜
39
+ string_cont_type1 = re.compile(r'", ""\), " ", \("')
40
+ string_cont_type2 = re.compile(r'", ""\), "", \("')
41
+ output = string_cont_type1.sub(' ', output)
42
+ output = string_cont_type2.sub(' ', output)
43
+
44
+ return output
45
+