Update app.py
Browse files
app.py
CHANGED
@@ -7,29 +7,6 @@ import os
|
|
7 |
# OpenAI API μ€μ (νκ²½ λ³μμμ μ½μ΄μ΄)
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY") # μ€μ μ½λμμ μ£Όμ ν΄μ
|
9 |
|
10 |
-
# μ€λ₯ μμ ν¨μ
|
11 |
-
def fix_response_errors(text):
|
12 |
-
if not text.startswith("annotated_text("):
|
13 |
-
text = "annotated_text(" + text
|
14 |
-
if not text.endswith(")"):
|
15 |
-
text += ")"
|
16 |
-
|
17 |
-
open_paren = text.count("(")
|
18 |
-
close_paren = text.count(")")
|
19 |
-
while open_paren > close_paren:
|
20 |
-
text += ")"
|
21 |
-
close_paren += 1
|
22 |
-
while open_paren < close_paren:
|
23 |
-
text = text.rsplit(")", 1)[0]
|
24 |
-
close_paren -= 1
|
25 |
-
|
26 |
-
quotes_count = text.count('"')
|
27 |
-
if quotes_count % 2 != 0:
|
28 |
-
text += '"'
|
29 |
-
|
30 |
-
return text
|
31 |
-
|
32 |
-
|
33 |
def main():
|
34 |
st.title("Keyword Highlighter")
|
35 |
|
@@ -107,7 +84,7 @@ def main():
|
|
107 |
# )"""
|
108 |
|
109 |
# user_prompt = f"Based on the task description, annotate the following text by highlighting key words about the topic: {user_text}"
|
110 |
-
user_prompt = f"First, extract key words for the topic
|
111 |
|
112 |
messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
|
113 |
|
@@ -121,14 +98,11 @@ def main():
|
|
121 |
presence_penalty=0
|
122 |
)
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
#
|
128 |
-
|
129 |
-
exec(fixed_response)
|
130 |
-
except Exception as e:
|
131 |
-
st.error(f"An error occurred: {e}")
|
132 |
|
133 |
|
134 |
|
|
|
7 |
# OpenAI API μ€μ (νκ²½ λ³μμμ μ½μ΄μ΄)
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY") # μ€μ μ½λμμ μ£Όμ ν΄μ
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def main():
|
11 |
st.title("Keyword Highlighter")
|
12 |
|
|
|
84 |
# )"""
|
85 |
|
86 |
# user_prompt = f"Based on the task description, annotate the following text by highlighting key words about the topic: {user_text}"
|
87 |
+
user_prompt = f"First, extract key words for the topic st-annotated-text format.: {user_text}"
|
88 |
|
89 |
messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
|
90 |
|
|
|
98 |
presence_penalty=0
|
99 |
)
|
100 |
|
101 |
+
highlighted_text = response['choices'][0]['message']['content']
|
102 |
+
|
103 |
+
# μ¬κΈ°μλ κ°λ¨νκ² exec ν¨μλ₯Ό μ΄μ©ν΄ GPT-3.5-turboκ° μμ±ν μ½λλ₯Ό μ€νν©λλ€.
|
104 |
+
# μ€μ νλ‘λμ
νκ²½μμλ 보μ μ΄μλ₯Ό κ³ λ €ν΄μΌ ν©λλ€.
|
105 |
+
exec(highlighted_text)
|
|
|
|
|
|
|
106 |
|
107 |
|
108 |
|