Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,27 +4,28 @@ import os
|
|
| 4 |
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/openchat/openchat-3.5-1210"
|
| 6 |
headers = {
|
| 7 |
-
"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" #
|
| 8 |
}
|
| 9 |
|
| 10 |
def smart_bot(message):
|
| 11 |
-
prompt = f"
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 15 |
|
| 16 |
if response.status_code == 200:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
return reply
|
| 20 |
-
except:
|
| 21 |
-
return "β Error: Unexpected response format"
|
| 22 |
else:
|
| 23 |
-
return "β Error:
|
| 24 |
|
| 25 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 26 |
gr.Markdown("<h1 style='text-align: center;'>π€ Tagalog-English Smart ChatBot</h1>")
|
| 27 |
-
gr.Markdown("<marquee style='color:black; font-weight:bold'>
|
| 28 |
|
| 29 |
with gr.Row():
|
| 30 |
user_input = gr.Textbox(label="π¬ Type your message here")
|
|
|
|
| 4 |
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/openchat/openchat-3.5-1210"
|
| 6 |
headers = {
|
| 7 |
+
"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" # SECRET dapat sa Hugging Face Spaces
|
| 8 |
}
|
| 9 |
|
| 10 |
def smart_bot(message):
|
| 11 |
+
prompt = f"""
|
| 12 |
+
Sumagot ka gamit ang parehong wika ng tanong (Tagalog kung Tagalog ang tanong, English kung English).
|
| 13 |
+
|
| 14 |
+
User: {message}
|
| 15 |
+
Assistant:"""
|
| 16 |
|
| 17 |
+
payload = {"inputs": prompt}
|
| 18 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 19 |
|
| 20 |
if response.status_code == 200:
|
| 21 |
+
reply = response.json()[0]["generated_text"].split("Assistant:")[-1].strip()
|
| 22 |
+
return reply
|
|
|
|
|
|
|
|
|
|
| 23 |
else:
|
| 24 |
+
return f"β Error: {response.status_code} - {response.text}"
|
| 25 |
|
| 26 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 27 |
gr.Markdown("<h1 style='text-align: center;'>π€ Tagalog-English Smart ChatBot</h1>")
|
| 28 |
+
gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using OpenChat 3.5</marquee>")
|
| 29 |
|
| 30 |
with gr.Row():
|
| 31 |
user_input = gr.Textbox(label="π¬ Type your message here")
|