Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,6 @@ df['text'] = df.apply(
|
|
26 |
lambda x: f"[{x['์ํผ์๋']}] #{x['row_id']} {x['type']} {x['scene_text']}",
|
27 |
axis=1
|
28 |
)
|
29 |
-
texts = df['text'].tolist()
|
30 |
|
31 |
# ====== FAISS ์์ ๋ก๋ ======
|
32 |
embedding_model = HuggingFaceEmbeddings(model_name='jhgan/ko-sroberta-multitask')
|
@@ -47,7 +46,7 @@ if load_path:
|
|
47 |
vectorstore = FAISS.load_local(load_path, embedding_model, allow_dangerous_deserialization=True)
|
48 |
print(f"[INFO] FAISS ์ธ๋ฑ์ค ๋ก๋ ์๋ฃ โ {load_path}")
|
49 |
else:
|
50 |
-
raise FileNotFoundError("FAISS index.faiss ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค.
|
51 |
|
52 |
# ====== ๋ชจ๋ธ ๋ก๋ (CPU ์ ์ฉ) ======
|
53 |
model_name = "kakaocorp/kanana-nano-2.1b-instruct"
|
@@ -70,17 +69,23 @@ qa_chain = RetrievalQA.from_chain_type(
|
|
70 |
chain_type_kwargs={"prompt": custom_prompt}
|
71 |
)
|
72 |
|
73 |
-
# ======
|
74 |
choices = [
|
75 |
-
"ํฉ๋์ ๋ฌด๋ฆฌ๋ฅผ ๋ชจ๋ ์ฒ์นํ๋ค.",
|
76 |
-
"์งํธ๋ฅผ ํฌํจํ ํฉ๋์ ๋ฌด๋ฆฌ๋ฅผ ๋ชจ๋ ์ฒ์นํ๋ค.",
|
77 |
-
"์ ๋ถ ๊ธฐ์ ์ํค๊ณ ์ด๋ ค๋๋ค.",
|
78 |
-
"์์คํ
์ ๊ฑฐ๋ถํ๊ณ ๊ทธ๋ฅ ๋๋ง์น๋ค."
|
79 |
]
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
result = qa_chain({"query": user_choice})
|
85 |
retrieved_context = "\n".join([doc.page_content for doc in result["source_documents"]])
|
86 |
|
@@ -94,15 +99,13 @@ def run_episode(selection):
|
|
94 |
"""
|
95 |
|
96 |
response = llm_pipeline(prompt)[0]["generated_text"]
|
97 |
-
return f"[์ฑ์ง์ฐ
|
98 |
-
|
99 |
-
# ====== Gradio
|
100 |
-
demo = gr.
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
title="์ฑ์ง์ฐ ์ ํ ์๋ฎฌ๋ ์ด์
",
|
105 |
-
description="๋ฒํธ๋ฅผ ์ ํํ๋ฉด ์ฑ์ง์ฐ์ ์๋ต์ด ์์ฑ๋ฉ๋๋ค."
|
106 |
)
|
107 |
|
108 |
if __name__ == "__main__":
|
|
|
26 |
lambda x: f"[{x['์ํผ์๋']}] #{x['row_id']} {x['type']} {x['scene_text']}",
|
27 |
axis=1
|
28 |
)
|
|
|
29 |
|
30 |
# ====== FAISS ์์ ๋ก๋ ======
|
31 |
embedding_model = HuggingFaceEmbeddings(model_name='jhgan/ko-sroberta-multitask')
|
|
|
46 |
vectorstore = FAISS.load_local(load_path, embedding_model, allow_dangerous_deserialization=True)
|
47 |
print(f"[INFO] FAISS ์ธ๋ฑ์ค ๋ก๋ ์๋ฃ โ {load_path}")
|
48 |
else:
|
49 |
+
raise FileNotFoundError("FAISS index.faiss ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
50 |
|
51 |
# ====== ๋ชจ๋ธ ๋ก๋ (CPU ์ ์ฉ) ======
|
52 |
model_name = "kakaocorp/kanana-nano-2.1b-instruct"
|
|
|
69 |
chain_type_kwargs={"prompt": custom_prompt}
|
70 |
)
|
71 |
|
72 |
+
# ====== ๋ํํ ์๋ต ํจ์ ======
|
73 |
choices = [
|
74 |
+
"1. ํฉ๋์ ๋ฌด๋ฆฌ๋ฅผ ๋ชจ๋ ์ฒ์นํ๋ค.",
|
75 |
+
"2. ์งํธ๋ฅผ ํฌํจํ ํฉ๋์ ๋ฌด๋ฆฌ๋ฅผ ๋ชจ๋ ์ฒ์นํ๋ค.",
|
76 |
+
"3. ์ ๋ถ ๊ธฐ์ ์ํค๊ณ ์ด๋ ค๋๋ค.",
|
77 |
+
"4. ์์คํ
์ ๊ฑฐ๋ถํ๊ณ ๊ทธ๋ฅ ๋๋ง์น๋ค."
|
78 |
]
|
79 |
|
80 |
+
def respond(message, history):
|
81 |
+
try:
|
82 |
+
sel_num = int(message.strip())
|
83 |
+
if sel_num < 1 or sel_num > len(choices):
|
84 |
+
return "โ ์ฌ๋ฐ๋ฅธ ๋ฒํธ๋ฅผ ์
๋ ฅํ์ธ์. (1~4)"
|
85 |
+
except ValueError:
|
86 |
+
return "โ ๋ฒํธ๋ฅผ ์
๋ ฅํ์ธ์. (์: 1, 2, 3, 4)"
|
87 |
+
|
88 |
+
user_choice = choices[sel_num - 1]
|
89 |
result = qa_chain({"query": user_choice})
|
90 |
retrieved_context = "\n".join([doc.page_content for doc in result["source_documents"]])
|
91 |
|
|
|
99 |
"""
|
100 |
|
101 |
response = llm_pipeline(prompt)[0]["generated_text"]
|
102 |
+
return f"[์ฑ์ง์ฐ]\n{response}"
|
103 |
+
|
104 |
+
# ====== Gradio ChatInterface ======
|
105 |
+
demo = gr.ChatInterface(
|
106 |
+
respond,
|
107 |
+
title="์ฑ์ง์ฐ ์ ํ ์๋ฎฌ๋ ์ด์
(์นด์นด์คํก ์คํ์ผ)",
|
108 |
+
description="1~4๋ฒ ์ค ํ๋๋ฅผ ์
๋ ฅํ๋ฉด ์ฑ์ง์ฐ์ ์๋ต์ด ๋ํ ํ์์ผ๋ก ๋ํ๋ฉ๋๋ค."
|
|
|
|
|
109 |
)
|
110 |
|
111 |
if __name__ == "__main__":
|