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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -1,12 +1,11 @@
1
- import os
2
  import gradio as gr
3
  import requests
 
4
 
5
  API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat"
6
- API_TOKEN = os.getenv("HF_API_TOKEN")
7
 
8
  headers = {
9
- "Authorization": f"Bearer {API_TOKEN}"
10
  }
11
 
12
  def smart_bot(message):
@@ -19,17 +18,14 @@ AI:"""
19
  response = requests.post(API_URL, headers=headers, json=payload)
20
 
21
  if response.status_code == 200:
22
- try:
23
- reply = response.json()[0]["generated_text"].split("AI:")[-1].strip()
24
- return reply
25
- except Exception:
26
- return "⚠️ Error: Unexpected response format."
27
  else:
28
  return "❌ Error: " + response.text
29
 
30
  with gr.Blocks(theme=gr.themes.Soft()) as app:
31
  gr.Markdown("<h1 style='text-align: center;'>🤖 Tagalog-English Smart ChatBot</h1>")
32
- gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using Hugging Face LLaMA 2</marquee>")
33
 
34
  with gr.Row():
35
  user_input = gr.Textbox(label="💬 Type your message here")
 
 
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):
 
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")