Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,26 @@ faq = {
|
|
12 |
]
|
13 |
}
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def chatbot(uid, question):
|
16 |
-
user_faq =
|
17 |
if not user_faq:
|
18 |
return "FAQ belum tersedia."
|
19 |
|
|
|
12 |
]
|
13 |
}
|
14 |
|
15 |
+
import requests
|
16 |
+
|
17 |
+
SUPABASE_URL = "https://olbjfxlclotxtnpjvpfj.supabase.co"
|
18 |
+
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9sYmpmeGxjbG90eHRucGp2cGZqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTIyMzYwMDEsImV4cCI6MjA2NzgxMjAwMX0.7q_o5DCFEAAysnWXMChH4MI5qNhIVc4OgpT5JvgYxc0" # anon key
|
19 |
+
|
20 |
+
def get_faq_from_supabase(uid):
|
21 |
+
url = f"{SUPABASE_URL}/rest/v1/faq_texts?uid=eq.{uid}"
|
22 |
+
headers = {
|
23 |
+
"apikey": SUPABASE_KEY,
|
24 |
+
"Authorization": f"Bearer {SUPABASE_KEY}",
|
25 |
+
"Content-Type": "application/json"
|
26 |
+
}
|
27 |
+
r = requests.get(url, headers=headers)
|
28 |
+
if r.status_code != 200:
|
29 |
+
return []
|
30 |
+
data = r.json()
|
31 |
+
return [{"q": item["question"], "a": item["answer"]} for item in data]
|
32 |
+
|
33 |
def chatbot(uid, question):
|
34 |
+
user_faq = get_faq_from_supabase(uid)
|
35 |
if not user_faq:
|
36 |
return "FAQ belum tersedia."
|
37 |
|