Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat"
|
| 6 |
|
|
|
|
| 7 |
headers = {
|
| 8 |
-
"Authorization":
|
| 9 |
}
|
| 10 |
|
| 11 |
def smart_bot(message):
|
| 12 |
-
prompt = f""
|
| 13 |
-
You are a friendly, helpful AI assistant. Reply in the same language as the question — Tagalog if the user types in Tagalog, English if in English. Use natural, polite tone.
|
| 14 |
-
User: {message}
|
| 15 |
-
AI:"""
|
| 16 |
-
|
| 17 |
payload = {"inputs": prompt}
|
| 18 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 19 |
-
|
| 20 |
if response.status_code == 200:
|
| 21 |
-
|
| 22 |
-
return
|
| 23 |
else:
|
| 24 |
-
return "
|
| 25 |
-
|
| 26 |
-
with gr.Blocks(
|
| 27 |
-
gr.Markdown("
|
| 28 |
-
gr.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
send_btn = gr.Button("Send")
|
| 33 |
-
bot_reply = gr.Textbox(label="🤖 Bot's Reply")
|
| 34 |
-
|
| 35 |
-
send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_reply)
|
| 36 |
|
| 37 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b"
|
| 5 |
headers = {
|
| 6 |
+
"Authorization": "Bearer hf_your_token_here"
|
| 7 |
}
|
| 8 |
|
| 9 |
def smart_bot(message):
|
| 10 |
+
prompt = f"You are a friendly AI assistant. Reply in the same language as the question.\nUser: {message}\nAI:"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
payload = {"inputs": prompt}
|
| 12 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 13 |
+
|
| 14 |
if response.status_code == 200:
|
| 15 |
+
# Depending on API output structure
|
| 16 |
+
return response.json()[0]['generated_text'].split("AI:")[-1].strip()
|
| 17 |
else:
|
| 18 |
+
return f"Error: {response.text}"
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as app:
|
| 21 |
+
gr.Markdown("# 🤖 Tagalog-English Chatbot")
|
| 22 |
+
user_input = gr.Textbox(label="Enter your message")
|
| 23 |
+
output = gr.Textbox(label="Bot reply")
|
| 24 |
+
send_btn = gr.Button("Send")
|
| 25 |
+
send_btn.click(fn=smart_bot, inputs=user_input, outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
app.launch()
|