Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -117,26 +117,26 @@ def get_faq_from_supabase(admin_id: str) -> List[Dict]:
|
|
117 |
|
118 |
# API Endpoints
|
119 |
@app.post("/predict")
|
120 |
-
|
121 |
-
async def predict(request: Request, data: List[str] = ["", ""]):
|
122 |
-
"""Get answer for user question"""
|
123 |
if len(data) != 2:
|
124 |
-
|
125 |
-
status_code=400,
|
126 |
-
detail="Invalid input format. Expected [admin_id, question]"
|
127 |
-
)
|
128 |
|
129 |
admin_id, question = data
|
130 |
-
if not
|
131 |
-
|
132 |
-
status_code=400,
|
133 |
-
detail="Admin ID and question are required"
|
134 |
-
)
|
135 |
|
136 |
-
# Get FAQs for this admin
|
137 |
faqs = get_faq_from_supabase(admin_id)
|
138 |
if not faqs:
|
139 |
-
return {"data": ["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
# Process question
|
142 |
questions = [f["question"] for f in faqs]
|
|
|
117 |
|
118 |
# API Endpoints
|
119 |
@app.post("/predict")
|
120 |
+
async def predict(data: List[str] = Body(...)):
|
|
|
|
|
121 |
if len(data) != 2:
|
122 |
+
return {"data": ["Format input tidak valid"]}
|
|
|
|
|
|
|
123 |
|
124 |
admin_id, question = data
|
125 |
+
if not question.strip():
|
126 |
+
return {"data": ["Pertanyaan tidak boleh kosong"]}
|
|
|
|
|
|
|
127 |
|
|
|
128 |
faqs = get_faq_from_supabase(admin_id)
|
129 |
if not faqs:
|
130 |
+
return {"data": ["Chatbot ini belum diisi FAQ oleh pemiliknya"]}
|
131 |
+
|
132 |
+
try:
|
133 |
+
# ... proses similarity seperti sebelumnya ...
|
134 |
+
if best_score < 0.3: # Threshold lebih rendah
|
135 |
+
return {"data": ["Tanyakan dengan lebih spesifik tentang layanan kami"]}
|
136 |
+
|
137 |
+
return {"data": [answers[best_idx]]}
|
138 |
+
except Exception:
|
139 |
+
return {"data": ["Sedang ada gangguan teknis, coba lagi nanti"]}
|
140 |
|
141 |
# Process question
|
142 |
questions = [f["question"] for f in faqs]
|