Liam2343 commited on
Commit
0555594
·
verified ·
1 Parent(s): 0e3a050

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -7
app.py CHANGED
@@ -2,6 +2,7 @@ import torch
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import gradio as gr
4
 
 
5
  model_name = "microsoft/DialoGPT-medium"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForCausalLM.from_pretrained(model_name)
@@ -32,12 +33,35 @@ def chat(user_input, history=[]):
32
  history.append((user_input, response))
33
  return history, history
34
 
35
- chatbot = gr.Chatbot()
36
- demo = gr.Interface(
37
- fn=chat,
38
- inputs=[gr.Textbox(placeholder="Say something..."), gr.State([])],
39
- outputs=[chatbot, gr.State()],
40
- title="DialoGPT Chat Assistant",
41
- )
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  demo.launch()
 
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import gradio as gr
4
 
5
+ # Load model
6
  model_name = "microsoft/DialoGPT-medium"
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForCausalLM.from_pretrained(model_name)
 
33
  history.append((user_input, response))
34
  return history, history
35
 
36
+ # Custom HTML Header
37
+ custom_html = """
38
+ <div style="text-align:center; padding: 20px; background-color: #1e1e2f; color: white; border-radius: 12px;">
39
+ <h1>🤖 Smart AI Assistant</h1>
40
+ <p>Talk to DialoGPT and experience AI conversation in real time.</p>
41
+ </div>
42
+ """
43
 
44
+ # Gradio Interface Setup
45
+ with gr.Blocks(theme="soft") as demo:
46
+ # Display the HTML header
47
+ gr.HTML(custom_html)
48
+
49
+ # Chatbot UI
50
+ chatbot = gr.Chatbot()
51
+
52
+ # Input Box and State for history
53
+ with gr.Row():
54
+ msg = gr.Textbox(placeholder="Say something...", elem_id="user-input")
55
+ state = gr.State([])
56
+
57
+ # Button for sending message
58
+ send_button = gr.Button("Send")
59
+
60
+ # Button click event to handle chat
61
+ send_button.click(fn=chat, inputs=[msg, state], outputs=[chatbot, state])
62
+
63
+ # Optional: Pressing 'Enter' key to send the message
64
+ msg.submit(fn=chat, inputs=[msg, state], outputs=[chatbot, state])
65
+
66
+ # Launch the Gradio interface
67
  demo.launch()