deepak191z commited on
Commit
d65702b
Β·
verified Β·
1 Parent(s): be3a356

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -32
app.py CHANGED
@@ -1,17 +1,14 @@
1
  import gradio as gr
2
 
3
- # Chatbot logic
4
  def respond(message, file, chat_history):
5
  if message:
6
  chat_history.append({"role": "user", "content": message})
7
  if file:
8
  chat_history.append({"role": "user", "content": f"πŸ“Ž File uploaded: {file.name}"})
9
- # Echo bot response
10
- response = f"πŸ€–: Got your message: {message or ''} {file.name if file else ''}"
11
- chat_history.append({"role": "assistant", "content": response})
12
  return "", None, chat_history
13
 
14
- # Custom CSS for layout
15
  custom_css = """
16
  .input-container {
17
  display: flex;
@@ -20,12 +17,16 @@ custom_css = """
20
  gap: 10px;
21
  margin-top: 10px;
22
  width: 100%;
 
 
23
  }
24
  .input-wrapper {
25
- flex-grow: 1;
26
  display: flex;
27
  align-items: center;
28
  gap: 10px;
 
 
 
29
  }
30
  .input-wrapper .icon {
31
  font-size: 20px;
@@ -41,6 +42,7 @@ custom_css = """
41
  background: none;
42
  border: none;
43
  color: #007bff;
 
44
  }
45
  """
46
 
@@ -48,41 +50,26 @@ with gr.Blocks(css=custom_css) as demo:
48
  chatbot = gr.Chatbot(type="messages")
49
  chat_history = gr.State([])
50
 
51
- # Input container with icons on both sides
 
 
 
52
  with gr.Row():
53
  with gr.Column(elem_classes="input-container"):
54
  with gr.Row(elem_classes="input-wrapper"):
55
- upload_btn = gr.UploadButton(
56
- label="πŸ“Ž",
57
- file_types=["*"],
58
- elem_classes="icon"
59
- )
60
  msg = gr.Textbox(
61
  label="",
62
  placeholder="Type your message...",
63
- scale=10,
64
  show_label=False,
65
- container=False
 
66
  )
67
  send_btn = gr.Button("➑️", elem_classes="send-button")
68
 
69
- # Submit on Enter or click send button
70
- msg.submit(
71
- respond,
72
- inputs=[msg, upload_btn, chat_history],
73
- outputs=[msg, upload_btn, chatbot]
74
- )
75
- send_btn.click(
76
- respond,
77
- inputs=[msg, upload_btn, chat_history],
78
- outputs=[msg, upload_btn, chatbot]
79
- )
80
-
81
- # Optional: Trigger response when file is uploaded
82
- upload_btn.upload(
83
- respond,
84
- inputs=[msg, upload_btn, chat_history],
85
- outputs=[msg, upload_btn, chatbot]
86
- )
87
 
88
  demo.queue().launch()
 
1
  import gradio as gr
2
 
 
3
  def respond(message, file, chat_history):
4
  if message:
5
  chat_history.append({"role": "user", "content": message})
6
  if file:
7
  chat_history.append({"role": "user", "content": f"πŸ“Ž File uploaded: {file.name}"})
8
+ chat_history.append({"role": "assistant", "content": "βœ… Got it!"})
 
 
9
  return "", None, chat_history
10
 
11
+ # Custom CSS for layout (responsive and overflow-safe)
12
  custom_css = """
13
  .input-container {
14
  display: flex;
 
17
  gap: 10px;
18
  margin-top: 10px;
19
  width: 100%;
20
+ max-width: 100%;
21
+ box-sizing: border-box;
22
  }
23
  .input-wrapper {
 
24
  display: flex;
25
  align-items: center;
26
  gap: 10px;
27
+ flex-grow: 1;
28
+ min-width: 0;
29
+ white-space: nowrap;
30
  }
31
  .input-wrapper .icon {
32
  font-size: 20px;
 
42
  background: none;
43
  border: none;
44
  color: #007bff;
45
+ flex-shrink: 0;
46
  }
47
  """
48
 
 
50
  chatbot = gr.Chatbot(type="messages")
51
  chat_history = gr.State([])
52
 
53
+ with gr.Row():
54
+ with gr.Column():
55
+ chatbot.render()
56
+
57
  with gr.Row():
58
  with gr.Column(elem_classes="input-container"):
59
  with gr.Row(elem_classes="input-wrapper"):
60
+ upload_btn = gr.UploadButton("πŸ“Ž", file_types=["*"], elem_classes="icon")
 
 
 
 
61
  msg = gr.Textbox(
62
  label="",
63
  placeholder="Type your message...",
 
64
  show_label=False,
65
+ container=False,
66
+ lines=1,
67
  )
68
  send_btn = gr.Button("➑️", elem_classes="send-button")
69
 
70
+ # Event handlers
71
+ msg.submit(respond, inputs=[msg, upload_btn, chat_history], outputs=[msg, upload_btn, chatbot])
72
+ send_btn.click(respond, inputs=[msg, upload_btn, chat_history], outputs=[msg, upload_btn, chatbot])
73
+ upload_btn.upload(respond, inputs=[msg, upload_btn, chat_history], outputs=[msg, upload_btn, chatbot])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  demo.queue().launch()