Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -66,6 +66,7 @@ compression_retriever = ContextualCompressionRetriever(
|
|
66 |
id_list = []
|
67 |
history = []
|
68 |
customer_data_list = []
|
|
|
69 |
context = "{context}"
|
70 |
question = "{question}"
|
71 |
|
@@ -84,25 +85,60 @@ def gen(x, id, customer_data):
|
|
84 |
index = len(id_list)
|
85 |
id_list.append(id)
|
86 |
customer_data_list.append(customer_data)
|
|
|
87 |
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n')
|
88 |
-
|
89 |
-
bot_str = f"νμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
90 |
return bot_str
|
91 |
else:
|
92 |
if x == "μ΄κΈ°ν":
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
97 |
elif x == "κ°μ
μ 보":
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
else:
|
101 |
context = "{context}"
|
102 |
question = "{question}"
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
106 |
|
107 |
[보νλͺ©λ‘]
|
108 |
λΌμ΄ννλλμ 기보νβ
‘
|
@@ -126,7 +162,7 @@ def gen(x, id, customer_data):
|
|
126 |
{context}
|
127 |
|
128 |
### λͺ
λ Ήμ΄:
|
129 |
-
λ€μ μ§μΉ¨μ μ°Έκ³ νμ¬ μλ΄μμΌλ‘μ κ³ κ°μκ² νμν μλ΅μ
|
130 |
[μ§μΉ¨]
|
131 |
1.κ³ κ°μ κ°μ
μ 보λ₯Ό κΌ νμΈνμ¬ κ³ κ°μ΄ κ°μ
ν 보νμ λν λ΄μ©λ§ μ 곡νμΈμ.
|
132 |
2.κ³ κ°μ΄ κ°μ
ν 보νμ΄λΌλ©΄ κ³ κ°μ μ§λ¬Έμ λν΄ μ μ ν λ΅λ³νμΈμ.
|
@@ -157,11 +193,15 @@ def gen(x, id, customer_data):
|
|
157 |
template=prompt_template,
|
158 |
)},
|
159 |
)
|
160 |
-
|
|
|
|
|
|
|
161 |
response = qa({"query":query})
|
162 |
-
output_str = response['result'].rsplit("."
|
163 |
-
print(prompt_template + output_str)
|
164 |
history[index] += f"κ³ κ°:{x}\nμλ΄μ:{output_str}\n"
|
|
|
|
|
165 |
return output_str
|
166 |
def reset_textbox():
|
167 |
return gr.update(value='')
|
@@ -188,4 +228,4 @@ with gr.Blocks() as demo:
|
|
188 |
label="customer_data"
|
189 |
)
|
190 |
button_submit.click(gen, [user_text, id_text, customer_data], model_output)
|
191 |
-
demo.queue().launch(enable_queue=True)
|
|
|
66 |
id_list = []
|
67 |
history = []
|
68 |
customer_data_list = []
|
69 |
+
customer_agree_list = []
|
70 |
context = "{context}"
|
71 |
question = "{question}"
|
72 |
|
|
|
85 |
index = len(id_list)
|
86 |
id_list.append(id)
|
87 |
customer_data_list.append(customer_data)
|
88 |
+
customer_agree_list.append("No")
|
89 |
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n')
|
90 |
+
bot_str = "* νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€. \n무μμ λμλ릴κΉμ?"
|
|
|
91 |
return bot_str
|
92 |
else:
|
93 |
if x == "μ΄κΈ°ν":
|
94 |
+
if customer_agree_list[index] != "No":
|
95 |
+
customer_data_list[index] = customer_data
|
96 |
+
bot_str = f"λνκΈ°λ‘μ΄ λͺ¨λ μ΄κΈ°νλμμ΅λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
97 |
+
return bot_str
|
98 |
+
else:
|
99 |
+
customer_data_list[index] = "κ°μ
μ 보μμ"
|
100 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
101 |
+
bot_str = f"λνκΈ°λ‘μ΄ λͺ¨λ μ΄κΈ°νλμμ΅λλ€.\n\n* νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
102 |
+
return bot_str
|
103 |
elif x == "κ°μ
μ 보":
|
104 |
+
if customer_agree_list[index] == "No":
|
105 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
106 |
+
bot_str = f"* νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
107 |
+
return bot_str
|
108 |
+
else:
|
109 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
110 |
+
bot_str = f"νμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data_list[index]}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
111 |
+
return bot_str
|
112 |
+
elif x == "μ½κ΄λμ_λμν¨":
|
113 |
+
if customer_agree_list[index] == "No":
|
114 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
115 |
+
customer_agree_list[index] = "Yes"
|
116 |
+
customer_data_list[index] = customer_data
|
117 |
+
bot_str = f"κ°μΈμ 보 νμ©μ λμνμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν©λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
118 |
+
return bot_str
|
119 |
+
else:
|
120 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
121 |
+
bot_str = f"μ΄λ―Έ μ½κ΄μ λμνμ
¨μ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
122 |
+
return bot_str
|
123 |
+
elif x == "μ½κ΄λμ_λμμν¨":
|
124 |
+
if customer_agree_list[index] == "Yes":
|
125 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
126 |
+
customer_agree_list[index] = "No"
|
127 |
+
customer_data_list[index] = "κ°μ
μ 보μμ"
|
128 |
+
bot_str = f"* κ°μΈμ 보 νμ© λμλ₯Ό μ·¨μνμ
¨μ΅λλ€. μ΄μ κ°μ
보νμ μ‘°νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
129 |
+
return bot_str
|
130 |
+
else:
|
131 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
132 |
+
bot_str = f"* κ°μΈμ 보 νμ©μ κ±°μ νμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν μ μμ΅λλ€. \n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
133 |
+
return bot_str
|
134 |
else:
|
135 |
context = "{context}"
|
136 |
question = "{question}"
|
137 |
+
if customer_agree_list[index] == "No":
|
138 |
+
customer_data_newline = "νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. μ½κ΄ λμκ° νμνλ€οΏ½οΏ½ μλ΄ν΄μ£ΌμΈμ."
|
139 |
+
else:
|
140 |
+
customer_data_newline = customer_data_list[index].replace(",","\n")
|
141 |
+
prompt_template = f"""λΉμ μ 보ν μλ΄μμ
λλ€. μλμ μ§λ¬Έκ³Ό κ΄λ ¨λ μ½κ΄ μ 보, μλ΅ μ§μΉ¨κ³Ό κ³ κ°μ 보ν κ°μ
μ 보, κ³ κ°κ³Όμ μλ΄κΈ°λ‘μ΄ μ£Όμ΄μ§λλ€. μμ²μ μ μ ν μλ£νλ μλ΅μ μμ±νμΈμ.
|
142 |
|
143 |
[보νλͺ©λ‘]
|
144 |
λΌμ΄ννλλμ 기보νβ
‘
|
|
|
162 |
{context}
|
163 |
|
164 |
### λͺ
λ Ήμ΄:
|
165 |
+
λ€μ μ§μΉ¨μ μ°Έκ³ νμ¬ μλ΄μμΌλ‘μ κ³ κ°μκ² νμν μλ΅μ μ 곡νμΈμ.
|
166 |
[μ§μΉ¨]
|
167 |
1.κ³ κ°μ κ°μ
μ 보λ₯Ό κΌ νμΈνμ¬ κ³ κ°μ΄ κ°μ
ν 보νμ λν λ΄μ©λ§ μ 곡νμΈμ.
|
168 |
2.κ³ κ°μ΄ κ°μ
ν 보νμ΄λΌλ©΄ κ³ κ°μ μ§λ¬Έμ λν΄ μ μ ν λ΅λ³νμΈμ.
|
|
|
193 |
template=prompt_template,
|
194 |
)},
|
195 |
)
|
196 |
+
if customer_agree_list[index] == "No":
|
197 |
+
query=f"{x}"
|
198 |
+
else:
|
199 |
+
query=f"{customer_data_list[index]}, {x}"
|
200 |
response = qa({"query":query})
|
201 |
+
output_str = response['result'].rsplit(".")[0] + "."
|
|
|
202 |
history[index] += f"κ³ κ°:{x}\nμλ΄μ:{output_str}\n"
|
203 |
+
if customer_agree_list[index] == "No":
|
204 |
+
output_str = f"* νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€." + output_str
|
205 |
return output_str
|
206 |
def reset_textbox():
|
207 |
return gr.update(value='')
|
|
|
228 |
label="customer_data"
|
229 |
)
|
230 |
button_submit.click(gen, [user_text, id_text, customer_data], model_output)
|
231 |
+
demo.queue().launch(enable_queue=True)
|