Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
headers = {
|
| 7 |
-
"Authorization": "Bearer hf_your_token_here" # β palitan mo ng token mo
|
| 8 |
-
}
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 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 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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
|
| 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 |
+
|