Noobjay commited on
Commit
67ed24a
Β·
verified Β·
1 Parent(s): e261970

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -1,31 +1,22 @@
1
  import gradio as gr
2
- import requests
 
3
 
4
- # Gamit ang public LLaMA-2 endpoint (REQUIRES TOKEN after accepting terms)
5
- API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat"
6
- headers = {
7
- "Authorization": "Bearer hf_your_token_here" # ← palitan mo ng token mo
8
- }
9
 
10
- def smart_bot(message):
11
- prompt = f"""
12
- 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.
13
-
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")
@@ -35,3 +26,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
35
  send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_reply)
36
 
37
  app.launch()
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
 
5
+ # Libre at public na chatbot model sa Hugging Face
6
+ model_name = "microsoft/DialoGPT-small"
 
 
 
7
 
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
 
 
 
 
10
 
11
+ def smart_bot(message):
12
+ inputs = tokenizer.encode(message + tokenizer.eos_token, return_tensors="pt")
13
+ reply_ids = model.generate(inputs, max_length=100, pad_token_id=tokenizer.eos_token_id)
14
+ reply = tokenizer.decode(reply_ids[:, inputs.shape[-1]:][0], skip_special_tokens=True)
15
+ return reply
16
 
17
  with gr.Blocks(theme=gr.themes.Soft()) as app:
18
+ gr.Markdown("<h1 style='text-align: center;'>πŸ€– Tagalog-English Smart ChatBot (Free Demo)</h1>")
19
+ gr.Markdown("<marquee style='color: black; font-weight: bold;'>Created by Niko Sedan - Using Microsoft DialoGPT</marquee>")
20
 
21
  with gr.Row():
22
  user_input = gr.Textbox(label="πŸ’¬ Type your message here")
 
26
  send_btn.click(fn=smart_bot, inputs=user_input, outputs=bot_reply)
27
 
28
  app.launch()
29
+