Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -425,40 +425,34 @@ def get_hf_user(token):
|
|
| 425 |
return "guest"
|
| 426 |
import re, json
|
| 427 |
|
| 428 |
-
def chat(message, history,
|
| 429 |
try:
|
| 430 |
# μμ€ν
λ©μμ§ ν¬ν¨ ν둬ννΈ κ΅¬μ±
|
| 431 |
-
prompt
|
| 432 |
|
| 433 |
-
raw_response = agent.
|
| 434 |
-
|
| 435 |
-
# λ¬Έμμ΄ λ³ν
|
| 436 |
text = str(raw_response)
|
| 437 |
|
| 438 |
-
# β
JSON
|
|
|
|
| 439 |
match = re.search(r"\{.*\}", text, re.DOTALL)
|
| 440 |
if match:
|
| 441 |
try:
|
| 442 |
obj = json.loads(match.group(0))
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
output = obj[k]
|
| 451 |
-
break
|
| 452 |
-
else:
|
| 453 |
-
output = text
|
| 454 |
except Exception:
|
| 455 |
output = text
|
| 456 |
-
else:
|
| 457 |
-
output = text
|
| 458 |
|
| 459 |
except Exception as e:
|
| 460 |
output = f"β οΈ μ€λ₯: {e}"
|
| 461 |
|
|
|
|
| 462 |
history = history + [(message, output)]
|
| 463 |
return history, history, ""
|
| 464 |
'''
|
|
|
|
| 425 |
return "guest"
|
| 426 |
import re, json
|
| 427 |
|
| 428 |
+
def chat(message, history,username="default_user"):
|
| 429 |
try:
|
| 430 |
# μμ€ν
λ©μμ§ ν¬ν¨ ν둬ννΈ κ΅¬μ±
|
| 431 |
+
prompt=message
|
| 432 |
|
| 433 |
+
raw_response = agent.run(prompt)
|
|
|
|
|
|
|
| 434 |
text = str(raw_response)
|
| 435 |
|
| 436 |
+
# β
JSON ννλ‘ μλ΅ μ νμ±
|
| 437 |
+
output = text
|
| 438 |
match = re.search(r"\{.*\}", text, re.DOTALL)
|
| 439 |
if match:
|
| 440 |
try:
|
| 441 |
obj = json.loads(match.group(0))
|
| 442 |
+
output = (
|
| 443 |
+
obj.get("action_input")
|
| 444 |
+
or obj.get("Final Answer")
|
| 445 |
+
or obj.get("output")
|
| 446 |
+
or obj.get("content")
|
| 447 |
+
or text
|
| 448 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
except Exception:
|
| 450 |
output = text
|
|
|
|
|
|
|
| 451 |
|
| 452 |
except Exception as e:
|
| 453 |
output = f"β οΈ μ€λ₯: {e}"
|
| 454 |
|
| 455 |
+
# β
Gradioμ© μ±ν
νμ μ
λ°μ΄νΈ
|
| 456 |
history = history + [(message, output)]
|
| 457 |
return history, history, ""
|
| 458 |
'''
|