Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637import gradio as grimport requestsimport osAPI_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat"headers = {"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}"}def smart_bot(message):prompt = f"""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.User: {message}AI:"""payload = {"inputs": prompt}response = requests.post(API_URL, headers=headers, json=payload)if response.status_code == 200:reply = response.json()[0]["generated_text"].split("AI:")[-1].strip()return replyelse:return "β Error: " + response.textwith 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 Hugging Face LLaMA-2</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()123456789101112131415161718192021222324252627import gradio as grimport requestsAPI_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b"headers = {"Authorization": "Bearer hf_your_token_here"}def smart_bot(message):prompt = f"You are a friendly AI assistant. Reply in the same language as the question.\nUser: {message}\nAI:"payload = {"inputs": prompt}response = requests.post(API_URL, headers=headers, json=payload)if response.status_code == 200:# Depending on API output structurereturn response.json()[0]['generated_text'].split("AI:")[-1].strip()else:return f"Error: {response.text}"with gr.Blocks() as app:gr.Markdown("# π€ Tagalog-English Chatbot")user_input = gr.Textbox(label="Enter your message")output = gr.Textbox(label="Bot reply")send_btn = gr.Button("Send")send_btn.click(fn=smart_bot, inputs=user_input, outputs=output)app.launch()
app.py+14-24