sibthinon commited on
Commit
7c23eb0
·
verified ·
1 Parent(s): f160890

add pyairtable

Browse files
Files changed (1) hide show
  1. app.py +20 -11
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
- now = datetime.now().isoformat()
122
- log_entry = {
123
- "timestamp": now,
124
- "model": latest_query_result["model"],
125
- "query": latest_query_result["query"],
126
- "result": latest_query_result["result"],
127
- "feedback": feedback
128
- }
129
- df = pd.DataFrame([log_entry])
130
- df.to_csv("feedback_log.csv", mode='a', header=not pd.io.common.file_exists("feedback_log.csv"), index=False)
131
- return f"✅ Feedback saved: {feedback}"
 
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