Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,9 @@ import os
|
|
| 3 |
import re
|
| 4 |
import csv
|
| 5 |
import tempfile
|
| 6 |
-
from
|
| 7 |
import datetime
|
| 8 |
import gradio as gr
|
| 9 |
-
from rapidfuzz import fuzz
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# Config / data loading
|
|
@@ -62,10 +61,8 @@ def infer_sentiment(user_text: str) -> str:
|
|
| 62 |
# Retrieval
|
| 63 |
# -----------------------------
|
| 64 |
def best_match_quote(user_text: str) -> str:
|
| 65 |
-
"""Search all categories, return best fuzzy match, fallback to random from any category."""
|
| 66 |
best_score = 0
|
| 67 |
best_quote = None
|
| 68 |
-
|
| 69 |
for cat, quotes_list in QUOTES.items():
|
| 70 |
for quote_entry in quotes_list:
|
| 71 |
quote = quote_entry.get("quote", "")
|
|
@@ -75,8 +72,6 @@ def best_match_quote(user_text: str) -> str:
|
|
| 75 |
if score > best_score:
|
| 76 |
best_score = score
|
| 77 |
best_quote = quote
|
| 78 |
-
|
| 79 |
-
# Threshold for unknown
|
| 80 |
if best_score < 30 or best_quote is None:
|
| 81 |
return f"No data about '{user_text}'"
|
| 82 |
return best_quote
|
|
@@ -179,8 +174,8 @@ with gr.Blocks() as demo:
|
|
| 179 |
clear.click(clear_chat, None, chatbot, queue=False)
|
| 180 |
|
| 181 |
upload_btn.upload(upload_json, upload_btn, [upload_status, category])
|
| 182 |
-
download_json_btn.download(download_current_json)
|
| 183 |
-
download_csv_btn.download(lambda: download_conversation_csv(chatbot.value))
|
| 184 |
|
| 185 |
# -----------------------------
|
| 186 |
# Startup log
|
|
|
|
| 3 |
import re
|
| 4 |
import csv
|
| 5 |
import tempfile
|
| 6 |
+
from rapidfuzz import fuzz
|
| 7 |
import datetime
|
| 8 |
import gradio as gr
|
|
|
|
| 9 |
|
| 10 |
# -----------------------------
|
| 11 |
# Config / data loading
|
|
|
|
| 61 |
# Retrieval
|
| 62 |
# -----------------------------
|
| 63 |
def best_match_quote(user_text: str) -> str:
|
|
|
|
| 64 |
best_score = 0
|
| 65 |
best_quote = None
|
|
|
|
| 66 |
for cat, quotes_list in QUOTES.items():
|
| 67 |
for quote_entry in quotes_list:
|
| 68 |
quote = quote_entry.get("quote", "")
|
|
|
|
| 72 |
if score > best_score:
|
| 73 |
best_score = score
|
| 74 |
best_quote = quote
|
|
|
|
|
|
|
| 75 |
if best_score < 30 or best_quote is None:
|
| 76 |
return f"No data about '{user_text}'"
|
| 77 |
return best_quote
|
|
|
|
| 174 |
clear.click(clear_chat, None, chatbot, queue=False)
|
| 175 |
|
| 176 |
upload_btn.upload(upload_json, upload_btn, [upload_status, category])
|
| 177 |
+
download_json_btn.download(lambda: download_current_json(), file_types=[".json"])
|
| 178 |
+
download_csv_btn.download(lambda: download_conversation_csv(chatbot.value), file_types=[".csv"])
|
| 179 |
|
| 180 |
# -----------------------------
|
| 181 |
# Startup log
|