Noobjay commited on
Commit
e2c6d83
Β·
verified Β·
1 Parent(s): 193f2dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -2,15 +2,14 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- API_URL = "https://api-inference.huggingface.co/models/openchat/openchat-3.5-1210"
6
  headers = {
7
- "Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" # SECRET dapat sa Hugging Face Spaces
8
  }
9
 
10
  def smart_bot(message):
11
  prompt = f"""
12
- Sumagot ka gamit ang parehong wika ng tanong (Tagalog kung Tagalog ang tanong, English kung English).
13
-
14
  User: {message}
15
  Assistant:"""
16
 
@@ -18,20 +17,21 @@ Assistant:"""
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("Assistant:")[-1].strip()
 
22
  return reply
23
  else:
24
- return f"❌ Error: {response.status_code} - {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 OpenChat 3.5</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()
 
2
  import requests
3
  import os
4
 
5
+ API_URL = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
6
  headers = {
7
+ "Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}" # Secret token sa Hugging Face settings
8
  }
9
 
10
  def smart_bot(message):
11
  prompt = f"""
12
+ You are a helpful AI assistant. Reply in the same language as the input.
 
13
  User: {message}
14
  Assistant:"""
15
 
 
17
  response = requests.post(API_URL, headers=headers, json=payload)
18
 
19
  if response.status_code == 200:
20
+ result = response.json()
21
+ reply = result[0]["generated_text"].split("Assistant:")[-1].strip()
22
  return reply
23
  else:
24
+ return f"❌ Error {response.status_code}: {response.text}"
25
 
26
  with gr.Blocks(theme=gr.themes.Soft()) as app:
27
+ gr.Markdown("<h1 style='text-align: center;'>πŸ€– Tagalog-English AI ChatBot</h1>")
28
+ gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan using Falcon 7B</marquee>")
29
 
30
  with gr.Row():
31
+ user_input = gr.Textbox(label="πŸ’¬ Your Message")
32
  send_btn = gr.Button("Send")
33
+ bot_output = gr.Textbox(label="πŸ€– Bot's Reply")
34
 
35
+ send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_output)
36
 
37
  app.launch()