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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -4,27 +4,28 @@ 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')}" # ← sa Secrets mo ito ilagay
8
  }
9
 
10
  def smart_bot(message):
11
- prompt = f"<|user|>\n{message}\n<|assistant|>"
12
- payload = {"inputs": prompt}
 
 
 
13
 
 
14
  response = requests.post(API_URL, headers=headers, json=payload)
15
 
16
  if response.status_code == 200:
17
- try:
18
- reply = response.json()[0]["generated_text"].split("<|assistant|>")[-1].strip()
19
- return reply
20
- except:
21
- return "❌ Error: Unexpected response format"
22
  else:
23
- return "❌ Error: " + response.text
24
 
25
  with gr.Blocks(theme=gr.themes.Soft()) as app:
26
  gr.Markdown("<h1 style='text-align: center;'>πŸ€– Tagalog-English Smart ChatBot</h1>")
27
- gr.Markdown("<marquee style='color:black; font-weight:bold'>Powered by OpenChat 3.5-1210</marquee>")
28
 
29
  with gr.Row():
30
  user_input = gr.Textbox(label="πŸ’¬ Type your message here")
 
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
 
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("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")