Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -56,7 +56,7 @@ class SimpleRAGSystem:
|
|
56 |
if count == 0:
|
57 |
raise RuntimeError("ChromaDB๊ฐ ๋น์ด์์ต๋๋ค.")
|
58 |
|
59 |
-
def search_similar_docs(self, query: str, top_k: int =
|
60 |
emb = self.embedding_model.encode(query).tolist()
|
61 |
res = self.collection.query(
|
62 |
query_embeddings=[emb], n_results=top_k,
|
@@ -71,21 +71,21 @@ rag_system = SimpleRAGSystem()
|
|
71 |
|
72 |
# === Google ADK ์ค์ ===
|
73 |
session_svc = InMemorySessionService()
|
74 |
-
agent = Agent(model="gemini-2.0-flash-lite"
|
75 |
name="khu_media_advisor",
|
76 |
instruction="""๋น์ ์ ๊ฒฝํฌ๋ํ๊ต ๋ฏธ๋์ดํ๊ณผ ์ ๋ฌธ ์๋ด AI์
๋๋ค.
|
77 |
# ์ฃผ์ ์ญํ :
|
78 |
-
- ์ ๊ณต๋ ๋ฌธ์ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก
|
79 |
- ๋ฏธ๋์ดํ๊ณผ ๊ด๋ จ ์ง๋ฌธ์ ์น์ ํ๊ณ ๊ตฌ์ฒด์ ์ผ๋ก ์๋ต
|
80 |
- ๋ฌธ์์ ์๋ ๋ด์ฉ์ ์ผ๋ฐ ์ง์์ผ๋ก ๋ณด์ (๋จ, ๋ช
์)
|
81 |
# ๋ต๋ณ ์คํ์ผ:
|
82 |
-
- ์์ธํ๊ณ ํ๋ถํ ์ค๋ช
์ ํฌํจํ์ฌ
|
83 |
- ์น๊ทผํ๊ณ ๋์์ด ๋๋ ์๋ด์ฌ ํค
|
84 |
- ํต์ฌ ์ ๋ณด๋ฅผ ๋ช
ํํ๊ฒ ์ ๋ฌ
|
85 |
- ์ถ๊ฐ ๊ถ๊ธํ ์ ์ด ์์ผ๋ฉด ์ธ์ ๋ ๋ฌผ์ด๋ณด๋ผ๊ณ ์๋ด
|
86 |
# ์ฐธ๊ณ ๋ฌธ์ ํ์ฉ:
|
87 |
- ๋ฌธ์ ๋ด์ฉ์ด ์์ผ๋ฉด ๊ตฌ์ฒด์ ์ผ๋ก ์ธ์ฉ
|
88 |
-
- ์ฌ๋ฌ ๋ฌธ์์ ์ ๋ณด๋ฅผ ์ข
ํฉํ์ฌ
|
89 |
- ์ ํํ์ง ์์ ์ ๋ณด๋ ์ถ์ธกํ์ง ๋ง๊ณ ์์งํ๊ฒ ๋ชจ๋ฅธ๋ค๊ณ ๋ต๋ณ"""
|
90 |
)
|
91 |
|
@@ -108,7 +108,7 @@ async def get_response(prompt: str) -> str:
|
|
108 |
with gr.Blocks(title="๊ฒฝํฌ๋ ๋ฏธ๋์ดํ๊ณผ AI ์๋ด์ฌ", theme="soft") as app:
|
109 |
gr.Markdown("# ๐ฌ ๊ฒฝํฌ๋ ๋ฏธ๋์ดํ๊ณผ AI ์๋ด์ฌ")
|
110 |
chatbot = gr.Chatbot(type="messages", height=400)
|
111 |
-
msg = gr.Textbox(show_label=False, placeholder="์ง๋ฌธ์ ์
๋ ฅํ์ธ์...")
|
112 |
send = gr.Button("์ ์ก")
|
113 |
|
114 |
def chat_fn(user_input, history):
|
@@ -116,10 +116,10 @@ with gr.Blocks(title="๊ฒฝํฌ๋ ๋ฏธ๋์ดํ๊ณผ AI ์๋ด์ฌ", theme="soft") as
|
|
116 |
# ์
๋ ฅ ์ ์ฒ๋ฆฌ: ์ค์ฉ ๋ฐฉ์ง
|
117 |
user_input = user_input.replace("์ ๊ณต", "๋ถ์ผ").replace("๊ต์", "๊ต์์ง")
|
118 |
# ๊ต์์ง ๊ด๋ จ ์ง๋ฌธ ์ฒ๋ฆฌ
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
# RAG ์ปจํ
์คํธ
|
124 |
docs = rag_system.search_similar_docs(user_input)
|
125 |
# Combine existing history (dicts) with new user message
|
|
|
56 |
if count == 0:
|
57 |
raise RuntimeError("ChromaDB๊ฐ ๋น์ด์์ต๋๋ค.")
|
58 |
|
59 |
+
def search_similar_docs(self, query: str, top_k: int = 20) -> List[Dict]:
|
60 |
emb = self.embedding_model.encode(query).tolist()
|
61 |
res = self.collection.query(
|
62 |
query_embeddings=[emb], n_results=top_k,
|
|
|
71 |
|
72 |
# === Google ADK ์ค์ ===
|
73 |
session_svc = InMemorySessionService()
|
74 |
+
agent = Agent(model="gemini-2.0-flash", # "gemini-2.0-flash-lite"
|
75 |
name="khu_media_advisor",
|
76 |
instruction="""๋น์ ์ ๊ฒฝํฌ๋ํ๊ต ๋ฏธ๋์ดํ๊ณผ ์ ๋ฌธ ์๋ด AI์
๋๋ค.
|
77 |
# ์ฃผ์ ์ญํ :
|
78 |
+
- ์ ๊ณต๋ ๋ฌธ์ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ๋ต๋ณ ์ ๊ณต
|
79 |
- ๋ฏธ๋์ดํ๊ณผ ๊ด๋ จ ์ง๋ฌธ์ ์น์ ํ๊ณ ๊ตฌ์ฒด์ ์ผ๋ก ์๋ต
|
80 |
- ๋ฌธ์์ ์๋ ๋ด์ฉ์ ์ผ๋ฐ ์ง์์ผ๋ก ๋ณด์ (๋จ, ๋ช
์)
|
81 |
# ๋ต๋ณ ์คํ์ผ:
|
82 |
+
- ์์ธํ๊ณ ํ๋ถํ ์ค๋ช
์ ํฌํจํ์ฌ ์์ธํ๊ณ ๊ธธ๊ฒ ๋ต๋ณ ์ ๊ณต
|
83 |
- ์น๊ทผํ๊ณ ๋์์ด ๋๋ ์๋ด์ฌ ํค
|
84 |
- ํต์ฌ ์ ๋ณด๋ฅผ ๋ช
ํํ๊ฒ ์ ๋ฌ
|
85 |
- ์ถ๊ฐ ๊ถ๊ธํ ์ ์ด ์์ผ๋ฉด ์ธ์ ๋ ๋ฌผ์ด๋ณด๋ผ๊ณ ์๋ด
|
86 |
# ์ฐธ๊ณ ๋ฌธ์ ํ์ฉ:
|
87 |
- ๋ฌธ์ ๋ด์ฉ์ด ์์ผ๋ฉด ๊ตฌ์ฒด์ ์ผ๋ก ์ธ์ฉ
|
88 |
+
- ์ฌ๋ฌ ๋ฌธ์์ ์ ๋ณด๋ฅผ ์ข
ํฉํ์ฌ ๋ต๋ณ ์์ฑ
|
89 |
- ์ ํํ์ง ์์ ์ ๋ณด๋ ์ถ์ธกํ์ง ๋ง๊ณ ์์งํ๊ฒ ๋ชจ๋ฅธ๋ค๊ณ ๋ต๋ณ"""
|
90 |
)
|
91 |
|
|
|
108 |
with gr.Blocks(title="๊ฒฝํฌ๋ ๋ฏธ๋์ดํ๊ณผ AI ์๋ด์ฌ", theme="soft") as app:
|
109 |
gr.Markdown("# ๐ฌ ๊ฒฝํฌ๋ ๋ฏธ๋์ดํ๊ณผ AI ์๋ด์ฌ")
|
110 |
chatbot = gr.Chatbot(type="messages", height=400)
|
111 |
+
msg = gr.Textbox(show_label=False, placeholder="์ด ๊ณณ์ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์...")
|
112 |
send = gr.Button("์ ์ก")
|
113 |
|
114 |
def chat_fn(user_input, history):
|
|
|
116 |
# ์
๋ ฅ ์ ์ฒ๋ฆฌ: ์ค์ฉ ๋ฐฉ์ง
|
117 |
user_input = user_input.replace("์ ๊ณต", "๋ถ์ผ").replace("๊ต์", "๊ต์์ง")
|
118 |
# ๊ต์์ง ๊ด๋ จ ์ง๋ฌธ ์ฒ๋ฆฌ
|
119 |
+
if "๊ต์์ง" in user_input or "๊ต์" in user_input:
|
120 |
+
prof_msg = f"ํ์ฌ ๋ฏธ๋์ดํ๊ณผ ๊ต์์ง์: {', '.join(PROFESSORS)} ์
๋๋ค."
|
121 |
+
history.append({"role": "assistant", "content": prof_msg})
|
122 |
+
return history,
|
123 |
# RAG ์ปจํ
์คํธ
|
124 |
docs = rag_system.search_similar_docs(user_input)
|
125 |
# Combine existing history (dicts) with new user message
|