Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,14 @@ import pandas as pd
|
|
6 |
from typing import List, Tuple
|
7 |
import json
|
8 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# νκ²½ λ³μ μ€μ
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
@@ -154,19 +162,58 @@ def read_uploaded_file(file):
|
|
154 |
except Exception as e:
|
155 |
return f"β νμΌ μ½κΈ° μ€λ₯: {str(e)}", "error"
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
|
158 |
if not message:
|
159 |
return "", history
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
3. π― μ§λ¬Έμ μλλ₯Ό μ νν νμ
νμ¬ λ§μΆ€ν λ΅λ³
|
165 |
-
4.
|
166 |
-
5. β¨
|
|
|
|
|
167 |
|
168 |
-
νμ μμ λ°λ₯΄κ³ μΉμ νκ² μλ΅νλ©°, νμν κ²½μ° κ΅¬μ²΄μ μΈ μμλ μ€λͺ
μ μΆκ°νμ¬
|
169 |
-
μ΄ν΄λ₯Ό λκ² μ΅λλ€."""
|
170 |
|
171 |
try:
|
172 |
# νμΌ μ
λ‘λ μ²λ¦¬
|
|
|
6 |
from typing import List, Tuple
|
7 |
import json
|
8 |
from datetime import datetime
|
9 |
+
from datasets import load_dataset
|
10 |
+
|
11 |
+
try:
|
12 |
+
pharmkg_dataset = load_dataset("vinven7/PharmKG")
|
13 |
+
print("PharmKG λ°μ΄ν°μ
λ‘λ μλ£")
|
14 |
+
except Exception as e:
|
15 |
+
print(f"PharmKG λ°μ΄ν°μ
λ‘λ μ€ν¨: {e}")
|
16 |
+
pharmkg_dataset = None
|
17 |
|
18 |
# νκ²½ λ³μ μ€μ
|
19 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
162 |
except Exception as e:
|
163 |
return f"β νμΌ μ½κΈ° μ€λ₯: {str(e)}", "error"
|
164 |
|
165 |
+
|
166 |
+
|
167 |
+
def get_pharmkg_context(query):
|
168 |
+
"""PharmKG λ°μ΄ν°μ
μμ κ΄λ ¨ μ 보 κ²μ"""
|
169 |
+
if pharmkg_dataset is None:
|
170 |
+
return ""
|
171 |
+
|
172 |
+
try:
|
173 |
+
# λ°μ΄ν°μ
μμ κ΄λ ¨ μ 보 κ²μ λ‘μ§ κ΅¬ν
|
174 |
+
relevant_info = []
|
175 |
+
|
176 |
+
# μ½λ¬Ό μ 보 κ²μ
|
177 |
+
for item in pharmkg_dataset['train']:
|
178 |
+
if query.lower() in str(item).lower():
|
179 |
+
relevant_info.append(str(item))
|
180 |
+
|
181 |
+
if relevant_info:
|
182 |
+
return "\n\nPharmKG μ°Έκ³ μ 보:\n" + "\n".join(relevant_info[:3])
|
183 |
+
return ""
|
184 |
+
except Exception as e:
|
185 |
+
print(f"PharmKG κ²μ μ€λ₯: {e}")
|
186 |
+
return ""
|
187 |
+
|
188 |
+
|
189 |
def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
|
190 |
if not message:
|
191 |
return "", history
|
192 |
|
193 |
+
try:
|
194 |
+
# PharmKG 컨ν
μ€νΈ μΆκ°
|
195 |
+
pharmkg_context = get_pharmkg_context(message)
|
196 |
+
system_message = SYSTEM_PREFIX + system_message + pharmkg_context
|
197 |
+
|
198 |
+
|
199 |
+
SYSTEM_PREFIX = """μ λ μ½λ¦¬ν μ λ¬Έ AI μ΄μμ€ν΄νΈ 'GiniGEN Pharm'μ
λλ€. PharmKG λ°μ΄ν°λ² μ΄μ€λ₯Ό κΈ°λ°μΌλ‘
|
200 |
+
λ€μκ³Ό κ°μ μ λ¬Έμ±μ κ°μ§κ³ μν΅νκ² μ΅λλ€:
|
201 |
+
|
202 |
+
1. π μ½λ¬Ό κ΄λ ¨ μ λ¬Έ μ§μ μ 곡
|
203 |
+
2. π¬ μ½λ¬Ό μνΈμμ© λ° λΆμμ© μ 보
|
204 |
+
3. 𧬠μ§λ³-μ½λ¬Ό κ΄κ³ μ€λͺ
|
205 |
+
4. π μμ λ°μ΄ν° κΈ°λ° λΆμ
|
206 |
+
5. βοΈ μμ½ν μμ μ± μ 보
|
207 |
+
|
208 |
+
λ€μ μμΉμΌλ‘ μν΅νκ² μ΅λλ€:
|
209 |
+
1. π€ μ λ¬Έμ μ΄κ³ μ λ’°ν μ μλ μ 보 μ 곡
|
210 |
+
2. π‘ μ΄ν΄νκΈ° μ¬μ΄ μ€λͺ
κ³Ό ν¨κ» κ³Όνμ κ·Όκ±° μ μ
|
211 |
3. π― μ§λ¬Έμ μλλ₯Ό μ νν νμ
νμ¬ λ§μΆ€ν λ΅λ³
|
212 |
+
4. β οΈ μλ£μ μ‘°μΈμ΄ μλ μ 보 μ 곡 λͺ©μ μμ λͺ
μ
|
213 |
+
5. β¨ μΆκ° μ°Έκ³ μλ£ λ° μ°κ΅¬ λ°μ΄ν° μ μ
|
214 |
+
|
215 |
+
μνμ κ²°μ μ λ°λμ μ λ¬Έ μλ£μ§κ³Ό μλ΄νμκΈ° λ°λλλ€."""
|
216 |
|
|
|
|
|
217 |
|
218 |
try:
|
219 |
# νμΌ μ
λ‘λ μ²λ¦¬
|