Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from threading import Thread
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
-
from llama_cpp import Llama
|
4 |
import torch
|
5 |
import gradio as gr
|
6 |
import re
|
@@ -52,7 +51,7 @@ docsearch = FAISS.load_local("", embeddings)
|
|
52 |
embeddings_filter = EmbeddingsFilter(
|
53 |
embeddings=embeddings,
|
54 |
similarity_threshold=0.7,
|
55 |
-
k =
|
56 |
)
|
57 |
# μμΆ κ²μκΈ° μμ±
|
58 |
compression_retriever = ContextualCompressionRetriever(
|
@@ -85,9 +84,14 @@ def gen(x, id, customer_data):
|
|
85 |
index = len(id_list)
|
86 |
id_list.append(id)
|
87 |
customer_data_list.append(customer_data)
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
91 |
return bot_str
|
92 |
else:
|
93 |
if x == "μ΄κΈ°ν":
|
@@ -162,7 +166,8 @@ def gen(x, id, customer_data):
|
|
162 |
{context}
|
163 |
|
164 |
### λͺ
λ Ήμ΄:
|
165 |
-
λ€μ μ§μΉ¨μ μ°Έκ³ νμ¬ μλ΄μμΌλ‘μ κ³ κ°μκ² νμν μλ΅μ μ 곡νμΈμ.
|
|
|
166 |
[μ§μΉ¨]
|
167 |
1.κ³ κ°μ κ°μ
μ 보λ₯Ό κΌ νμΈνμ¬ κ³ κ°μ΄ κ°μ
ν 보νμ λν λ΄μ©λ§ μ 곡νμΈμ.
|
168 |
2.κ³ κ°μ΄ κ°μ
ν 보νμ΄λΌλ©΄ κ³ κ°μ μ§λ¬Έμ λν΄ μ μ ν λ΅λ³νμΈμ.
|
@@ -199,6 +204,8 @@ def gen(x, id, customer_data):
|
|
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
|
@@ -228,4 +235,4 @@ with gr.Blocks() as demo:
|
|
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)
|
|
|
1 |
from threading import Thread
|
2 |
from huggingface_hub import hf_hub_download
|
|
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
import re
|
|
|
51 |
embeddings_filter = EmbeddingsFilter(
|
52 |
embeddings=embeddings,
|
53 |
similarity_threshold=0.7,
|
54 |
+
k = 3,
|
55 |
)
|
56 |
# μμΆ κ²μκΈ° μμ±
|
57 |
compression_retriever = ContextualCompressionRetriever(
|
|
|
84 |
index = len(id_list)
|
85 |
id_list.append(id)
|
86 |
customer_data_list.append(customer_data)
|
87 |
+
if x != "μ½κ΄λμ_λμν¨":
|
88 |
+
customer_agree_list.append("No")
|
89 |
+
history.append('μλ΄μ:무μμ λμλ릴κΉμ?\n')
|
90 |
+
bot_str = "* νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€. \n무μμ λμλ릴κΉμ?"
|
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 == "μ΄κΈ°ν":
|
|
|
166 |
{context}
|
167 |
|
168 |
### λͺ
λ Ήμ΄:
|
169 |
+
λ€μ μ§μΉ¨μ μ°Έκ³ νμ¬ μλ΄μμΌλ‘μ κ³ κ°μκ² νμν μλ΅μ μ΅λν μμΈνκ² μ 곡νμΈμ.
|
170 |
+
|
171 |
[μ§μΉ¨]
|
172 |
1.κ³ κ°μ κ°μ
μ 보λ₯Ό κΌ νμΈνμ¬ κ³ κ°μ΄ κ°μ
ν 보νμ λν λ΄μ©λ§ μ 곡νμΈμ.
|
173 |
2.κ³ κ°μ΄ κ°μ
ν 보νμ΄λΌλ©΄ κ³ κ°μ μ§λ¬Έμ λν΄ μ μ ν λ΅λ³νμΈμ.
|
|
|
204 |
query=f"{customer_data_list[index]}, {x}"
|
205 |
response = qa({"query":query})
|
206 |
output_str = response['result'].rsplit(".")[0] + "."
|
207 |
+
if output_str.split(":")[0]=="μλ΄μ":
|
208 |
+
output_str = output_str.split(":")[1]
|
209 |
history[index] += f"κ³ κ°:{x}\nμλ΄μ:{output_str}\n"
|
210 |
if customer_agree_list[index] == "No":
|
211 |
output_str = f"* νμ¬ κ°μ
μ 보λ₯Ό μ‘°νν μ μμ΅λλ€. λ¨Όμ κ°μΈμ 보 μ΄μ© μ½κ΄μ λμνμ
μΌ μνν μλ΄μ μ§νν μ μμ΅λλ€." + output_str
|
|
|
235 |
label="customer_data"
|
236 |
)
|
237 |
button_submit.click(gen, [user_text, id_text, customer_data], model_output)
|
238 |
+
demo.queue().launch(enable_queue=True)
|