Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,14 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
| 6 |
headers = {
|
| 7 |
-
"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" #
|
| 8 |
}
|
| 9 |
|
| 10 |
def smart_bot(message):
|
| 11 |
prompt = f"""
|
| 12 |
-
|
| 13 |
-
|
| 14 |
User: {message}
|
| 15 |
Assistant:"""
|
| 16 |
|
|
@@ -18,20 +17,21 @@ Assistant:"""
|
|
| 18 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 19 |
|
| 20 |
if response.status_code == 200:
|
| 21 |
-
|
|
|
|
| 22 |
return reply
|
| 23 |
else:
|
| 24 |
-
return f"β Error
|
| 25 |
|
| 26 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 27 |
-
gr.Markdown("<h1 style='text-align: center;'>π€ Tagalog-English
|
| 28 |
-
gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using
|
| 29 |
|
| 30 |
with gr.Row():
|
| 31 |
-
user_input = gr.Textbox(label="π¬
|
| 32 |
send_btn = gr.Button("Send")
|
| 33 |
-
|
| 34 |
|
| 35 |
-
send_btn.click(fn=smart_bot, inputs=user_input, outputs=
|
| 36 |
|
| 37 |
app.launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
|
| 6 |
headers = {
|
| 7 |
+
"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" # Secret token sa Hugging Face settings
|
| 8 |
}
|
| 9 |
|
| 10 |
def smart_bot(message):
|
| 11 |
prompt = f"""
|
| 12 |
+
You are a helpful AI assistant. Reply in the same language as the input.
|
|
|
|
| 13 |
User: {message}
|
| 14 |
Assistant:"""
|
| 15 |
|
|
|
|
| 17 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 18 |
|
| 19 |
if response.status_code == 200:
|
| 20 |
+
result = response.json()
|
| 21 |
+
reply = result[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 AI ChatBot</h1>")
|
| 28 |
+
gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using Falcon 7B</marquee>")
|
| 29 |
|
| 30 |
with gr.Row():
|
| 31 |
+
user_input = gr.Textbox(label="π¬ Your Message")
|
| 32 |
send_btn = gr.Button("Send")
|
| 33 |
+
bot_output = gr.Textbox(label="π€ Bot's Reply")
|
| 34 |
|
| 35 |
+
send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_output)
|
| 36 |
|
| 37 |
app.launch()
|