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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -19
app.py CHANGED
@@ -6,25 +6,40 @@ def respond(message, file, chat_history):
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 (replace this with real logic)
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-row {
17
  display: flex;
18
  align-items: center;
 
19
  gap: 10px;
20
- margin-bottom: 10px;
 
21
  }
22
- .file-upload {
 
 
 
 
 
 
23
  font-size: 20px;
24
  cursor: pointer;
25
  color: #555;
26
  }
27
- .file-upload:hover {
 
 
 
 
 
 
 
28
  color: #007bff;
29
  }
30
  """
@@ -33,27 +48,37 @@ with gr.Blocks(css=custom_css) as demo:
33
  chatbot = gr.Chatbot(type="messages")
34
  chat_history = gr.State([])
35
 
36
- with gr.Row(elem_classes="input-row"):
37
- msg = gr.Textbox(
38
- label="",
39
- placeholder="Type your message...",
40
- scale=10,
41
- show_label=False
42
- )
43
- upload_btn = gr.UploadButton(
44
- label="πŸ“Ž",
45
- file_types=["*"],
46
- elem_classes="file-upload"
47
- )
 
 
 
 
 
48
 
49
- # Submit on Enter
50
  msg.submit(
51
  respond,
52
  inputs=[msg, upload_btn, chat_history],
53
  outputs=[msg, upload_btn, chatbot]
54
  )
 
 
 
 
 
55
 
56
- # Upload button triggers response
57
  upload_btn.upload(
58
  respond,
59
  inputs=[msg, upload_btn, chat_history],
 
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;
18
  align-items: center;
19
+ justify-content: space-between;
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;
32
  cursor: pointer;
33
  color: #555;
34
  }
35
+ .input-wrapper .icon:hover {
36
+ color: #007bff;
37
+ }
38
+ .send-button {
39
+ font-size: 20px;
40
+ cursor: pointer;
41
+ background: none;
42
+ border: none;
43
  color: #007bff;
44
  }
45
  """
 
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],