Spaces:
Runtime error
Runtime error
- app.py +28 -31
- gpt_based_function.py +1 -1
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
from gpt_based_function import gpt_keyw_extractor
|
@@ -8,7 +9,8 @@ import os, sys
|
|
8 |
# sys.path.append(current_path)
|
9 |
|
10 |
# OpenAI API μ€μ (νκ²½ λ³μμμ μ½μ΄μ΄)
|
11 |
-
openai.api_key =
|
|
|
12 |
st.set_page_config(layout="wide")
|
13 |
|
14 |
|
@@ -20,8 +22,29 @@ preset_learning_text = """λ―Όμ£Όμ£Όμ μ¬νλ κ΅λ―Όμ΄ μ μΉμ μ°Έμ¬ν
|
|
20 |
λ°λ©΄ μ무 ν¬νμ μ λ°λνλ μΈ‘μ νμ¬ μ°λ¦¬λλΌμ ν¬νμ¨μ΄ μ μΉ μ§λμλ€μ λνμ±μ νΌμν λ§νΌ μ¬κ°ν μν©μ μλλΌκ³ μ£Όμ₯νλ€. λ ν¬νμ¨μ λμ΄λ κ²λ³΄λ€ κ΅λ―Όμ μ λ’°λ₯Ό ν볡νλ κ²μ΄ λ μ€μνκ³ , μλ―Ό κ΅μ‘μ΄λ λͺ¨μ ν¬ν κ΅μ‘ νλ‘κ·Έλ¨μΌλ‘λ ν¬νμ¨ μμΉμ κΈ°λν μ μλ€λ©° μ무 ν¬νμ μ λμ
λ§μ΄ ν¬νμ¨μ΄λ μ μΉμ κ΄μ¬μ λμ΄λ ν΄κ²° λ°©μμ μλλΌκ³ μ΄μΌκΈ°νλ€. κ·Έλ¦¬κ³ μ무 ν¬νμ λ₯Ό λμ
νλ©΄, μ μΆλ μ μΉμΈλ€μ΄ λμ ν¬νμ¨μ νκ³λ‘ μν무μΈμ νλλ₯Ό κ°λ λΆμμ©μ΄ μκΈ΄λ€λ κ° ν보μλ₯Ό μ λͺ¨λ₯΄λ μνμμ ν¬ννλ μΌμ΄ λ°μνμ¬ κ΅λ―Όμ λ»μ΄ μ€νλ € μ곑λ μ μλ€λ©° μ°λ €μ λͺ©μ리λ₯Ό λ΄κ³ μλ€.
|
21 |
"""
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def display_passage(col):
|
24 |
st.header("μ§λ¬Έ")
|
|
|
25 |
global text_container
|
26 |
text_container = st.container() # μΆκ°λ μ½λ
|
27 |
# 미리 κ³΅κ° ν보
|
@@ -69,10 +92,11 @@ def display_summary(col):
|
|
69 |
|
70 |
def display_input_btns(col):
|
71 |
st.header("μΈκ³΅μ§λ₯ μ¬μ©νκΈ°")
|
|
|
72 |
global user_input
|
73 |
user_input = st.text_area("λ΄μ©μ λ£κ³ λ²νΌμ λλ¬μ£ΌμΈμ:", "")
|
74 |
st.write(user_input)
|
75 |
-
|
76 |
# λ²νΌ row
|
77 |
cols = st.columns(4)
|
78 |
with cols[0]:
|
@@ -80,11 +104,12 @@ def display_input_btns(col):
|
|
80 |
if btn_keyword:
|
81 |
# ν€μλ μ°ΎκΈ° λ‘μ§
|
82 |
# highlighted_text = gpt_keyw_extractor(preset_learning_text) # Should Be DELETED
|
83 |
-
|
84 |
highlighted_text = highlighted_texts_list[-1]
|
85 |
|
86 |
# κΈ°μ‘΄ μ§λ¬Έ μ§μ°κΈ°
|
87 |
text_placeholder.empty()
|
|
|
88 |
# μλ‘μ΄ λ΄μ© λ£κΈ°
|
89 |
with text_container:
|
90 |
exec(highlighted_text)
|
@@ -176,34 +201,6 @@ def main():
|
|
176 |
|
177 |
col1, col2 = st.columns(2)
|
178 |
|
179 |
-
## μμνκΈ° λ²νΌ μΆκ°
|
180 |
-
btn_start = st.button("μμνκΈ°")
|
181 |
-
if btn_start:
|
182 |
-
# ν€μλ μ°ΎκΈ° μ€νν΄μ λ³μμ keep
|
183 |
-
# preset_keyw_func(preset_learning_texts)
|
184 |
-
global preset_learning_text
|
185 |
-
preset_learning_texts = preset_learning_text.split("\n")
|
186 |
-
|
187 |
-
global highlighted_texts_list
|
188 |
-
highlighted_texts_list = list()
|
189 |
-
tmp = str()
|
190 |
-
for k in range(len(preset_learning_texts)):
|
191 |
-
print(k)
|
192 |
-
text = preset_learning_texts[k]
|
193 |
-
if tmp:
|
194 |
-
|
195 |
-
if len(text) > 15:
|
196 |
-
front_bared_htext = preset_learning_texts[k][15:] #15 = len('annotated_text(')
|
197 |
-
tmp = tmp[:-1] + front_bared_htext
|
198 |
-
else:
|
199 |
-
break # μ΄ λ¬Έλ¨μ == len(highlighted_text_list)-1
|
200 |
-
else:
|
201 |
-
tmp += text
|
202 |
-
highlighted_texts_list.append(gpt_keyw_extractor(tmp))
|
203 |
-
|
204 |
-
# μ¬μ΄ νν μ€νν΄μ λ³μμ keep
|
205 |
-
pass
|
206 |
-
|
207 |
with col1:
|
208 |
display_passage(col1)
|
209 |
display_summary(col1)
|
|
|
1 |
+
from annotated_text import annotated_text
|
2 |
import streamlit as st
|
3 |
import openai
|
4 |
from gpt_based_function import gpt_keyw_extractor
|
|
|
9 |
# sys.path.append(current_path)
|
10 |
|
11 |
# OpenAI API μ€μ (νκ²½ λ³μμμ μ½μ΄μ΄)
|
12 |
+
openai.api_key = "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"
|
13 |
+
# openai.api_key = os.getenv("OPENAI_API_KEY") # μ€μ μ½λμμ μ£Όμ ν΄μ
|
14 |
st.set_page_config(layout="wide")
|
15 |
|
16 |
|
|
|
22 |
λ°λ©΄ μ무 ν¬νμ μ λ°λνλ μΈ‘μ νμ¬ μ°λ¦¬λλΌμ ν¬νμ¨μ΄ μ μΉ μ§λμλ€μ λνμ±μ νΌμν λ§νΌ μ¬κ°ν μν©μ μλλΌκ³ μ£Όμ₯νλ€. λ ν¬νμ¨μ λμ΄λ κ²λ³΄λ€ κ΅λ―Όμ μ λ’°λ₯Ό ν볡νλ κ²μ΄ λ μ€μνκ³ , μλ―Ό κ΅μ‘μ΄λ λͺ¨μ ν¬ν κ΅μ‘ νλ‘κ·Έλ¨μΌλ‘λ ν¬νμ¨ μμΉμ κΈ°λν μ μλ€λ©° μ무 ν¬νμ μ λμ
λ§μ΄ ν¬νμ¨μ΄λ μ μΉμ κ΄μ¬μ λμ΄λ ν΄κ²° λ°©μμ μλλΌκ³ μ΄μΌκΈ°νλ€. κ·Έλ¦¬κ³ μ무 ν¬νμ λ₯Ό λμ
νλ©΄, μ μΆλ μ μΉμΈλ€μ΄ λμ ν¬νμ¨μ νκ³λ‘ μν무μΈμ νλλ₯Ό κ°λ λΆμμ©μ΄ μκΈ΄λ€λ κ° ν보μλ₯Ό μ λͺ¨λ₯΄λ μνμμ ν¬ννλ μΌμ΄ λ°μνμ¬ κ΅λ―Όμ λ»μ΄ μ€νλ € μ곑λ μ μλ€λ©° μ°λ €μ λͺ©μ리λ₯Ό λ΄κ³ μλ€.
|
23 |
"""
|
24 |
|
25 |
+
# ν€μλ μ°ΎκΈ° μ€νν΄μ λ³μμ keep
|
26 |
+
# preset_keyw_func(preset_learning_texts)
|
27 |
+
preset_learning_texts = preset_learning_text.split("\n")
|
28 |
+
|
29 |
+
highlighted_texts_list = list()
|
30 |
+
tmp = str()
|
31 |
+
for k in range(len(preset_learning_texts)):
|
32 |
+
print(k)
|
33 |
+
text = preset_learning_texts[k]
|
34 |
+
if tmp:
|
35 |
+
|
36 |
+
if len(text) > 15:
|
37 |
+
front_bared_htext = preset_learning_texts[k][15:] # 15 = len('annotated_text(')
|
38 |
+
tmp = tmp[:-1] + front_bared_htext
|
39 |
+
else:
|
40 |
+
break # μ΄ λ¬Έλ¨μ == len(highlighted_text_list)-1
|
41 |
+
else:
|
42 |
+
tmp += text
|
43 |
+
highlighted_texts_list.append(gpt_keyw_extractor(tmp))
|
44 |
+
|
45 |
def display_passage(col):
|
46 |
st.header("μ§λ¬Έ")
|
47 |
+
|
48 |
global text_container
|
49 |
text_container = st.container() # μΆκ°λ μ½λ
|
50 |
# 미리 κ³΅κ° ν보
|
|
|
92 |
|
93 |
def display_input_btns(col):
|
94 |
st.header("μΈκ³΅μ§λ₯ μ¬μ©νκΈ°")
|
95 |
+
|
96 |
global user_input
|
97 |
user_input = st.text_area("λ΄μ©μ λ£κ³ λ²νΌμ λλ¬μ£ΌμΈμ:", "")
|
98 |
st.write(user_input)
|
99 |
+
|
100 |
# λ²νΌ row
|
101 |
cols = st.columns(4)
|
102 |
with cols[0]:
|
|
|
104 |
if btn_keyword:
|
105 |
# ν€μλ μ°ΎκΈ° λ‘μ§
|
106 |
# highlighted_text = gpt_keyw_extractor(preset_learning_text) # Should Be DELETED
|
107 |
+
global highlighted_texts_list
|
108 |
highlighted_text = highlighted_texts_list[-1]
|
109 |
|
110 |
# κΈ°μ‘΄ μ§λ¬Έ μ§μ°κΈ°
|
111 |
text_placeholder.empty()
|
112 |
+
|
113 |
# μλ‘μ΄ λ΄μ© λ£κΈ°
|
114 |
with text_container:
|
115 |
exec(highlighted_text)
|
|
|
201 |
|
202 |
col1, col2 = st.columns(2)
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
with col1:
|
205 |
display_passage(col1)
|
206 |
display_summary(col1)
|
gpt_based_function.py
CHANGED
@@ -5,7 +5,7 @@ from text_annotator import generate_annotated_text
|
|
5 |
def gpt_keyw_extractor(user_text):
|
6 |
'''
|
7 |
:param user_text: str
|
8 |
-
:return:
|
9 |
'''
|
10 |
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."
|
11 |
|
|
|
5 |
def gpt_keyw_extractor(user_text):
|
6 |
'''
|
7 |
:param user_text: str
|
8 |
+
:return: annotated_text: str
|
9 |
'''
|
10 |
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."
|
11 |
|