Noobjay commited on
Commit
ec162ba
·
verified ·
1 Parent(s): 5da70f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -24
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": f"Bearer {os.getenv('HF_API_TOKEN')}"
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
- reply = response.json()[0]["generated_text"].split("AI:")[-1].strip()
22
- return reply
23
  else:
24
- return "❌ Error: " + response.text
25
-
26
- with gr.Blocks(theme=gr.themes.Soft()) as app:
27
- gr.Markdown("<h1 style='text-align: center;'>🤖 Tagalog-English Smart ChatBot</h1>")
28
- gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using Hugging Face LLaMA-2</marquee>")
29
-
30
- with gr.Row():
31
- user_input = gr.Textbox(label="💬 Type your message here")
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()