Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line23456789101112131415161 unmodified line18192021222324252627282930313233343536371 unmodified lineimport requestsimport osAPI_URL = "https://api-inference.huggingface.co/models/openchat/openchat-3.5-1210"headers = {"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" # SECRET dapat sa Hugging Face Spaces}def smart_bot(message):prompt = f"""Sumagot ka gamit ang parehong wika ng tanong (Tagalog kung Tagalog ang tanong, English kung English).User: {message}Assistant:"""1 unmodified lineresponse = requests.post(API_URL, headers=headers, json=payload)if response.status_code == 200:reply = response.json()[0]["generated_text"].split("Assistant:")[-1].strip()return replyelse:return f"β Error: {response.status_code} - {response.text}"with gr.Blocks(theme=gr.themes.Soft()) as app:gr.Markdown("<h1 style='text-align: center;'>π€ Tagalog-English Smart ChatBot</h1>")gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using OpenChat 3.5</marquee>")with gr.Row():user_input = gr.Textbox(label="π¬ Type your message here")send_btn = gr.Button("Send")bot_reply = gr.Textbox(label="π€ Bot's Reply")send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_reply)app.launch()1 unmodified line234567891011121314151 unmodified line1718192021222324252627282930313233343536371 unmodified lineimport requestsimport osAPI_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"headers = {"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" # Secret token sa Hugging Face settings}def smart_bot(message):prompt = f"""You are a helpful AI assistant. Reply in the same language as the input.User: {message}Assistant:"""1 unmodified lineresponse = 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 replyelse:return f"β Error {response.status_code}: {response.text}"with gr.Blocks(theme=gr.themes.Soft()) 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>")with gr.Row():user_input = gr.Textbox(label="π¬ Your Message")send_btn = gr.Button("Send")bot_output = gr.Textbox(label="π€ Bot's Reply")send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_output)app.launch()
app.py+11-11