Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-small")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Chat function
|
| 8 |
-
def respond(message):
|
| 9 |
-
result = chatbot(message, max_length=100, do_sample=True)[0]["generated_text"]
|
| 10 |
-
return result
|
| 11 |
-
|
| 12 |
-
# Interface design
|
| 13 |
-
with gr.Blocks() as app:
|
| 14 |
-
gr.Markdown("""
|
| 15 |
-
<marquee style="color:black; background-color:white; padding:5px; font-weight:bold;">
|
| 16 |
-
π€ AI ChatBot powered by microsoft/DialoGPT-small | Created by Niko Jay Sedan with help from AI
|
| 17 |
-
</marquee>
|
| 18 |
-
""")
|
| 19 |
-
gr.Markdown("## π€ Tagalog-English AI ChatBot")
|
| 20 |
-
gr.Markdown("Chat with this bot like you're messaging a virtual assistant.")
|
| 21 |
-
|
| 22 |
with gr.Row():
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, set_seed
|
| 3 |
+
import random
|
| 4 |
|
| 5 |
+
# Load chatbot model
|
| 6 |
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-small")
|
| 7 |
+
set_seed(42)
|
| 8 |
+
|
| 9 |
+
def chat(prompt):
|
| 10 |
+
response = chatbot(prompt, max_length=100, pad_token_id=50256)
|
| 11 |
+
return response[0]['generated_text'][len(prompt):]
|
| 12 |
+
|
| 13 |
+
# Running text and app description
|
| 14 |
+
banner_html = """
|
| 15 |
+
<div style='background:#000;color:#fff;padding:5px;overflow:hidden;white-space:nowrap'>
|
| 16 |
+
<marquee behavior="scroll" direction="left">π€ AI ChatBot App by Niko Jay Sedan β Powered by Hugging Face and Transformers β Tagalog and English Supported!</marquee>
|
| 17 |
+
</div>
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
with gr.Blocks(css="body { background-color: #f4f4f4; font-family: Arial; }") as demo:
|
| 21 |
+
gr.HTML(banner_html)
|
| 22 |
+
gr.Markdown("## π€ AI ChatBot Assistant\nType or speak in English or Tagalog. The bot will respond smartly!")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
with gr.Row():
|
| 25 |
+
txt_input = gr.Textbox(label="π€ Say or type something", placeholder="Halimbawa: Kamusta ka?", lines=2)
|
| 26 |
+
mic_btn = gr.Audio(source="microphone", type="filepath", label="π Or Speak")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
btn = gr.Button("Send")
|
| 30 |
+
response_output = gr.Textbox(label="π¬ Bot Reply")
|
| 31 |
+
|
| 32 |
+
def handle_input(text):
|
| 33 |
+
return chat(text)
|
| 34 |
+
|
| 35 |
+
btn.click(fn=handle_input, inputs=txt_input, outputs=response_output)
|
| 36 |
|
| 37 |
+
demo.launch()
|