Spaces:
Sleeping
Sleeping
Download app.py from Noobjay/AIChatbotV2: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/Noobjay/AIChatbotV2/resolve/main/app.py
- Command line
-
hf download hf://spaces/Noobjay/AIChatbotV2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Noobjay/AIChatbotV2/resolve/main/app.py
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() | |