SHAILJA1 commited on
Commit
54f12cf
·
verified ·
1 Parent(s): 2daac60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load lightweight model to avoid memory issues (you can replace it with Falcon or others)
5
  generator = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", device_map="auto", max_new_tokens=200)
6
 
7
  def respond(message, chat_history):
@@ -11,15 +11,16 @@ def respond(message, chat_history):
11
  chat_history.append((message, response))
12
  return "", chat_history
13
 
14
- # Create Gradio app with Submit button
15
  with gr.Blocks() as demo:
16
- gr.Markdown("## 🗨️ Falcon Chatbot with Submit Button")
17
- chatbot = gr.Chatbot()
18
- msg = gr.Textbox(placeholder="Enter your message here", label="Your Message")
19
- submit = gr.Button("Submit")
 
20
  state = gr.State([])
21
 
22
- # Bind button click and Enter key
23
  submit.click(fn=respond, inputs=[msg, state], outputs=[msg, chatbot])
24
  msg.submit(fn=respond, inputs=[msg, state], outputs=[msg, chatbot])
25
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load a lightweight open-access model
5
  generator = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", device_map="auto", max_new_tokens=200)
6
 
7
  def respond(message, chat_history):
 
11
  chat_history.append((message, response))
12
  return "", chat_history
13
 
14
+ # Gradio Blocks interface with Submit button
15
  with gr.Blocks() as demo:
16
+ gr.Markdown("## 🤖 Falcon-7B Chatbot with Submit Button")
17
+ chatbot = gr.Chatbot(label="Chat")
18
+ with gr.Row():
19
+ msg = gr.Textbox(placeholder="Type your message here...", show_label=False, scale=8)
20
+ submit = gr.Button("Submit", scale=2)
21
  state = gr.State([])
22
 
23
+ # Bind submit button and Enter key
24
  submit.click(fn=respond, inputs=[msg, state], outputs=[msg, chatbot])
25
  msg.submit(fn=respond, inputs=[msg, state], outputs=[msg, chatbot])
26