Noobjay commited on
Commit
7f3bd71
Β·
verified Β·
1 Parent(s): 1a118a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -23
app.py CHANGED
@@ -1,29 +1,37 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Gumamit ng libreng AI chatbot model
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
- input_box = gr.Textbox(label="You", placeholder="Type your message here...")
24
- output_box = gr.Textbox(label="Bot")
25
-
26
- btn = gr.Button("Send")
27
- btn.click(fn=respond, inputs=input_box, outputs=output_box)
 
 
 
 
 
 
28
 
29
- app.launch()
 
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()