AIChatbotV2 / app.py
Noobjay's picture
Update app.py
f0ff02a verified
Raw History Blame Contribute Delete
1.16 kB
import gradio as gr
import requests
import os
API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
headers = {
"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}"
}
def smart_bot(message):
prompt = f"""
You are a helpful assistant. Reply in the same language as the user input.
User: {message}
Assistant:"""
payload = {"inputs": prompt}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
reply = result[0]["generated_text"].split("Assistant:")[-1].strip()
return reply
else:
return f"❌ Error {response.status_code}: {response.text}"
with gr.Blocks() as app:
gr.Markdown("<h1 style='text-align: center;'>πŸ€– Tagalog-English AI ChatBot</h1>")
gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using Falcon 7B</marquee>")
user_input = gr.Textbox(label="πŸ’¬ Your Message")
bot_output = gr.Textbox(label="πŸ€– Bot's Reply")
send_btn = gr.Button("Send")
send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_output)
app.launch()