Spaces:
Sleeping
Sleeping
add pyairtable
Browse files
app.py
CHANGED
|
@@ -8,6 +8,8 @@ from qdrant_client.models import Filter, FieldCondition, MatchValue
|
|
| 8 |
import os
|
| 9 |
from symspellpy.symspellpy import SymSpell, Verbosity
|
| 10 |
from pythainlp.tokenize import word_tokenize
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
qdrant_client = QdrantClient(
|
|
@@ -15,6 +17,12 @@ qdrant_client = QdrantClient(
|
|
| 15 |
api_key=os.environ.get("Qdrant_api"),
|
| 16 |
)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# โมเดลที่โหลดล่วงหน้า
|
| 19 |
models = {
|
| 20 |
"E5 (intfloat/multilingual-e5-small)": SentenceTransformer('intfloat/multilingual-e5-small'),
|
|
@@ -118,17 +126,18 @@ def search_product(query, model_name):
|
|
| 118 |
|
| 119 |
# 📝 Logging feedback
|
| 120 |
def log_feedback(feedback):
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
# 🎨 Gradio UI
|
|
|
|
| 8 |
import os
|
| 9 |
from symspellpy.symspellpy import SymSpell, Verbosity
|
| 10 |
from pythainlp.tokenize import word_tokenize
|
| 11 |
+
from pyairtable import Table
|
| 12 |
+
from pyairtable import Api
|
| 13 |
|
| 14 |
|
| 15 |
qdrant_client = QdrantClient(
|
|
|
|
| 17 |
api_key=os.environ.get("Qdrant_api"),
|
| 18 |
)
|
| 19 |
|
| 20 |
+
AIRTABLE_API_KEY = os.environ.get("airtable_api")
|
| 21 |
+
BASE_ID = os.environ.get("airtable_baseid")
|
| 22 |
+
TABLE_NAME = "Feedback_search"
|
| 23 |
+
api = Api(AIRTABLE_API_KEY)
|
| 24 |
+
table = api.table(BASE_ID, TABLE_NAME)
|
| 25 |
+
|
| 26 |
# โมเดลที่โหลดล่วงหน้า
|
| 27 |
models = {
|
| 28 |
"E5 (intfloat/multilingual-e5-small)": SentenceTransformer('intfloat/multilingual-e5-small'),
|
|
|
|
| 126 |
|
| 127 |
# 📝 Logging feedback
|
| 128 |
def log_feedback(feedback):
|
| 129 |
+
try:
|
| 130 |
+
now = datetime.now().strftime("%Y-%m-%d")
|
| 131 |
+
table.create({
|
| 132 |
+
"timestamp": now,
|
| 133 |
+
"model": latest_query_result["model"],
|
| 134 |
+
"query": latest_query_result["query"],
|
| 135 |
+
"result": latest_query_result["result"],
|
| 136 |
+
"feedback": feedback
|
| 137 |
+
})
|
| 138 |
+
return "✅ Feedback saved to Airtable!"
|
| 139 |
+
except Exception as e:
|
| 140 |
+
return f"❌ Failed to save feedback: {str(e)}"
|
| 141 |
|
| 142 |
|
| 143 |
# 🎨 Gradio UI
|