Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -51,7 +51,7 @@ docsearch = FAISS.load_local("", embeddings)
|
|
51 |
embeddings_filter = EmbeddingsFilter(
|
52 |
embeddings=embeddings,
|
53 |
similarity_threshold=0.7,
|
54 |
-
k =
|
55 |
)
|
56 |
# μμΆ κ²μκΈ° μμ±
|
57 |
compression_retriever = ContextualCompressionRetriever(
|
@@ -86,64 +86,63 @@ def gen(x, id, customer_data):
|
|
86 |
customer_data_list.append(customer_data)
|
87 |
if x != "μ½κ΄λμ_λμν¨":
|
88 |
customer_agree_list.append("No")
|
89 |
-
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n')
|
90 |
-
bot_str = "*
|
91 |
else:
|
92 |
customer_agree_list.append("Yes")
|
93 |
-
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n')
|
94 |
bot_str = f"κ°μΈμ 보 νμ©μ λμνμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν©λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
95 |
return bot_str
|
96 |
else:
|
97 |
if x == "μ΄κΈ°ν":
|
98 |
if customer_agree_list[index] != "No":
|
99 |
customer_data_list[index] = customer_data
|
100 |
-
history[index] = 'μλ΄μ:\n무μμ λμλ릴κΉμ?\n\n'
|
101 |
bot_str = f"λνκΈ°λ‘μ΄ λͺ¨λ μ΄κΈ°νλμμ΅λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
102 |
return bot_str
|
103 |
else:
|
104 |
customer_data_list[index] = "κ°μ
μ 보μμ"
|
105 |
-
history[index] = '
|
106 |
-
bot_str = f"λνκΈ°λ‘μ΄ λͺ¨λ μ΄κΈ°νλμμ΅λλ€.\n\n*
|
107 |
return bot_str
|
108 |
elif x == "κ°μ
μ 보":
|
109 |
if customer_agree_list[index] == "No":
|
110 |
-
history[index] = '
|
111 |
-
bot_str = f"*
|
112 |
return bot_str
|
113 |
else:
|
114 |
-
history[index] = '
|
115 |
bot_str = f"νμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data_list[index]}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
116 |
return bot_str
|
117 |
elif x == "μ½κ΄λμ_λμν¨":
|
118 |
if customer_agree_list[index] == "No":
|
119 |
-
history[index] = '
|
120 |
customer_agree_list[index] = "Yes"
|
121 |
customer_data_list[index] = customer_data
|
122 |
bot_str = f"κ°μΈμ 보 νμ©μ λμνμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν©λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
123 |
return bot_str
|
124 |
else:
|
125 |
-
history[index] = '
|
126 |
bot_str = f"μ΄λ―Έ μ½κ΄μ λμνμ
¨μ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
127 |
return bot_str
|
128 |
elif x == "μ½κ΄λμ_λμμν¨":
|
129 |
if customer_agree_list[index] == "Yes":
|
130 |
-
history[index] = '
|
131 |
customer_agree_list[index] = "No"
|
132 |
customer_data_list[index] = "κ°μ
μ 보μμ"
|
133 |
bot_str = f"* κ°μΈμ 보 νμ© λμλ₯Ό μ·¨μνμ
¨μ΅λλ€. οΏ½οΏ½οΏ½μ κ°μ
보νμ μ‘°νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
134 |
return bot_str
|
135 |
else:
|
136 |
-
history[index] = '
|
137 |
bot_str = f"* κ°μΈμ 보 νμ©μ κ±°μ νμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν μ μμ΅λλ€. \n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
138 |
return bot_str
|
139 |
else:
|
140 |
context = "{context}"
|
141 |
question = "{question}"
|
142 |
if customer_agree_list[index] == "No":
|
143 |
-
customer_data_newline = "νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€.
|
144 |
else:
|
145 |
customer_data_newline = customer_data_list[index].replace(",","\n")
|
146 |
-
prompt_template = f"""λΉμ μ 보ν μλ΄μμ
λλ€. μλμ μ§λ¬Έκ³Ό κ΄λ ¨λ μ½κ΄ μ 보,
|
147 |
|
148 |
[μ 체 보ν λͺ©λ‘]
|
149 |
λΌμ΄ννλλμ 기보νβ
‘
|
@@ -164,32 +163,24 @@ def gen(x, id, customer_data):
|
|
164 |
1λ
λΆν°μ μΆλ³΄ν
|
165 |
λΌμ΄ννλλμ°κΈλ³΄νβ
‘
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
### λͺ
λ Ήμ΄:
|
170 |
-
λ€μ μ§μΉ¨μ μ°Έκ³ νμ¬ μλ΄μμΌλ‘μ κ³ κ°μκ² νμν μλ΅μ μ΅λν κΈΈκ³ μμΈνκ² μ 곡νμΈμ.
|
171 |
|
172 |
-
|
173 |
-
1.λ°λμ κΈΈκ³ μμΈνκ³ μΉμ νκ² μ 보λ₯Ό μ 곡νμΈμ.
|
174 |
-
2.κ³ κ°μ κ°μ
μ 보λ₯Ό κΌ νμΈνμ¬ κ³ κ°μ΄ κ°μ
ν 보νμ λν λ΄μ©λ§ μ 곡νμΈμ.
|
175 |
-
3.κ³ κ°μ΄ κ°μ
ν 보νμ΄λΌλ©΄ κ³ κ°μ μ§λ¬Έμ λν΄ μ μ ν λ΅λ³νμΈμ.
|
176 |
-
4.κ³ κ°μ΄ κ°μ
νμ§ μμ 보νμ 보μμ κ΄ν μ§λ¬Έμ κ΄λ ¨ 보νμ μκ°νλ©° 보μμ΄ λΆκ°λ₯νλ€λ μ μ μλ΄νμΈμ.
|
177 |
-
5.κ³ κ°μ΄ κ°μ
νμ§ μμ 보νμ κ°μ
μ΄ νμνλ€κ³ 보νλͺ
μ νμ€νκ² μΈκΈνμΈμ.
|
178 |
-
λ€μ μ
λ ₯μ μ£Όμ΄μ§λ κ³ κ°μ 보ν κ°μ
μ 보μ μλ΄ κΈ°λ‘μ λ³΄κ³ κ³ κ°μκ² λμλλ μ 보λ₯Ό μ 곡νμΈμ. μ°¨κ·Όμ°¨κ·Ό μκ°νμ¬ λ΅λ³νμΈμ. λΉμ μ μ ν μ μμ΅λλ€.
|
179 |
|
180 |
-
### μ
λ ₯:
|
181 |
[κ³ κ°μ κ°μ
μ 보]
|
182 |
{customer_data_newline}
|
183 |
|
184 |
-
|
185 |
-
|
186 |
|
187 |
-
|
188 |
{question}
|
189 |
|
190 |
-
|
191 |
-
|
|
|
192 |
|
|
|
193 |
"""
|
194 |
|
195 |
# RetrievalQA ν΄λμ€μ from_chain_typeμ΄λΌλ ν΄λμ€ λ©μλλ₯Ό νΈμΆνμ¬ μ§μμλ΅ κ°μ²΄λ₯Ό μμ±
|
@@ -207,14 +198,14 @@ def gen(x, id, customer_data):
|
|
207 |
if customer_agree_list[index] == "No":
|
208 |
query=f"{x}"
|
209 |
else:
|
210 |
-
query=f"{
|
211 |
response = qa({"query":query})
|
212 |
-
output_str = response['result'].rsplit(".")[0] + "."
|
213 |
if output_str.split(":")[0]=="μλ΄μ":
|
214 |
output_str = output_str.split(":")[1]
|
215 |
-
history[index] += f"
|
216 |
if customer_agree_list[index] == "No":
|
217 |
-
output_str = f"*
|
218 |
return output_str
|
219 |
def reset_textbox():
|
220 |
return gr.update(value='')
|
|
|
51 |
embeddings_filter = EmbeddingsFilter(
|
52 |
embeddings=embeddings,
|
53 |
similarity_threshold=0.7,
|
54 |
+
k = 2,
|
55 |
)
|
56 |
# μμΆ κ²μκΈ° μμ±
|
57 |
compression_retriever = ContextualCompressionRetriever(
|
|
|
86 |
customer_data_list.append(customer_data)
|
87 |
if x != "μ½κ΄λμ_λμν¨":
|
88 |
customer_agree_list.append("No")
|
89 |
+
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n\n')
|
90 |
+
bot_str = "* λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€. \n무μμ λμλ릴κΉμ?"
|
91 |
else:
|
92 |
customer_agree_list.append("Yes")
|
93 |
+
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n\n')
|
94 |
bot_str = f"κ°μΈμ 보 νμ©μ λμνμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν©λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
95 |
return bot_str
|
96 |
else:
|
97 |
if x == "μ΄κΈ°ν":
|
98 |
if customer_agree_list[index] != "No":
|
99 |
customer_data_list[index] = customer_data
|
|
|
100 |
bot_str = f"λνκΈ°λ‘μ΄ λͺ¨λ μ΄κΈ°νλμμ΅λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
101 |
return bot_str
|
102 |
else:
|
103 |
customer_data_list[index] = "κ°μ
μ 보μμ"
|
104 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n\n'
|
105 |
+
bot_str = f"λνκΈ°λ‘μ΄ λͺ¨λ μ΄κΈ°νλμμ΅λλ€.\n\n* λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
106 |
return bot_str
|
107 |
elif x == "κ°μ
μ 보":
|
108 |
if customer_agree_list[index] == "No":
|
109 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n\n'
|
110 |
+
bot_str = f"* λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
111 |
return bot_str
|
112 |
else:
|
113 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
114 |
bot_str = f"νμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data_list[index]}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
115 |
return bot_str
|
116 |
elif x == "μ½κ΄λμ_λμν¨":
|
117 |
if customer_agree_list[index] == "No":
|
118 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n\n'
|
119 |
customer_agree_list[index] = "Yes"
|
120 |
customer_data_list[index] = customer_data
|
121 |
bot_str = f"κ°μΈμ 보 νμ©μ λμνμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν©λλ€.\n\nνμ¬ κ³ κ°λκ»μ κ°μ
λ 보νμ {customer_data}μ
λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
122 |
return bot_str
|
123 |
else:
|
124 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n'
|
125 |
bot_str = f"μ΄λ―Έ μ½κ΄μ λμνμ
¨μ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
126 |
return bot_str
|
127 |
elif x == "μ½κ΄λμ_λμμν¨":
|
128 |
if customer_agree_list[index] == "Yes":
|
129 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n\n'
|
130 |
customer_agree_list[index] = "No"
|
131 |
customer_data_list[index] = "κ°μ
μ 보μμ"
|
132 |
bot_str = f"* κ°μΈμ 보 νμ© λμλ₯Ό μ·¨μνμ
¨μ΅λλ€. οΏ½οΏ½οΏ½μ κ°μ
보νμ μ‘°νν μ μμ΅λλ€.\n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
133 |
return bot_str
|
134 |
else:
|
135 |
+
history[index] = 'μλ΄μ:무μμ λμλ릴κΉμ?\n\n'
|
136 |
bot_str = f"* κ°μΈμ 보 νμ©μ κ±°μ νμ
¨μ΅λλ€. κ°μ
보νμ μ‘°νν μ μμ΅λλ€. \n\nκΆκΈνμ κ²μ΄ μμΌμ κ°μ?"
|
137 |
return bot_str
|
138 |
else:
|
139 |
context = "{context}"
|
140 |
question = "{question}"
|
141 |
if customer_agree_list[index] == "No":
|
142 |
+
customer_data_newline = "νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. κ°μ
ν μ μλ κ΄λ ¨ 보νμ μμ λͺ©λ‘μμ μκ°ν΄μ£ΌμΈμ."
|
143 |
else:
|
144 |
customer_data_newline = customer_data_list[index].replace(",","\n")
|
145 |
+
prompt_template = f"""λΉμ μ 보ν μλ΄μμ
λλ€. μλμ μ 체 보ν λͺ©λ‘, μ§λ¬Έκ³Ό κ΄λ ¨λ μ½κ΄ μ 보, κ³ κ°μ 보ν κ°μ
μ 보, κ³ κ°κ³Όμ μλ΄κΈ°λ‘μ΄ μ£Όμ΄μ§λλ€. μμ²μ μ μ ν μλ£νλ μλ΅μ μμ±νμΈμ. μμ±λ λ¬Έμ₯μΌλ‘ κ°κ²°ν λ΅νμΈμ.
|
146 |
|
147 |
[μ 체 보ν λͺ©λ‘]
|
148 |
λΌμ΄ννλλμ 기보νβ
‘
|
|
|
163 |
1λ
λΆν°μ μΆλ³΄ν
|
164 |
λΌμ΄ννλλμ°κΈλ³΄νβ
‘
|
165 |
|
166 |
+
κ³ κ°μ 보ν λͺ©λ‘κ³Ό μ½κ΄μ λ³Ό μ μμ΅λλ€. μ§μ μ μνμ¬ μκ°νμΈμ.
|
|
|
|
|
|
|
167 |
|
168 |
+
{context}
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
|
|
170 |
[κ³ κ°μ κ°μ
μ 보]
|
171 |
{customer_data_newline}
|
172 |
|
173 |
+
### λͺ
λ Ήμ΄:
|
174 |
+
μ£Όμ΄μ§λ μ΄μ λνλ₯Ό λ³΄κ³ λ§₯λ½μ νμ
νμ¬ μλ΄μμΌλ‘μ κ³ κ°μκ² νμν μ 보λ₯Ό μ΅λν κΈΈκ³ μμΈνκ³ μΉμ νκ² μ 곡νμΈμ. μΌλ°μ μΈ λ³΄ν κ΄λ ¨ μ§μμ ν΄λΉ λ΄μ©λ§ κ°κ²°ν λ΅λ³νμΈμ.
|
175 |
|
176 |
+
### μ§λ¬Έ:
|
177 |
{question}
|
178 |
|
179 |
+
### μ
λ ₯:
|
180 |
+
[μ΄μ λν]
|
181 |
+
{history[index]}
|
182 |
|
183 |
+
### μλ΅:
|
184 |
"""
|
185 |
|
186 |
# RetrievalQA ν΄λμ€μ from_chain_typeμ΄λΌλ ν΄λμ€ λ©μλλ₯Ό νΈμΆνμ¬ μ§μμλ΅ κ°μ²΄λ₯Ό μμ±
|
|
|
198 |
if customer_agree_list[index] == "No":
|
199 |
query=f"{x}"
|
200 |
else:
|
201 |
+
query=f"{x}"
|
202 |
response = qa({"query":query})
|
203 |
+
output_str = response['result'].rsplit(".",1)[0] + "."
|
204 |
if output_str.split(":")[0]=="μλ΄μ":
|
205 |
output_str = output_str.split(":")[1]
|
206 |
+
history[index] += f"κ³ κ°:{x}\n\nμλ΄μ:{output_str}\n\n"
|
207 |
if customer_agree_list[index] == "No":
|
208 |
+
output_str = f"* λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€.\n\n" + output_str
|
209 |
return output_str
|
210 |
def reset_textbox():
|
211 |
return gr.update(value='')
|