jimmy-yo commited on
Commit
18798f1
·
verified ·
1 Parent(s): 04ac23c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -10,7 +10,7 @@ from transformers import AutoProcessor, AutoModelForVision2Seq, TextIteratorStre
10
  # =======================
11
  # Runtime / model config
12
  # =======================
13
- DEVICE = "cpu"
14
  DTYPE = torch.float32
15
  MODEL_ID = "Qwen/Qwen2-VL-2B-Instruct"
16
 
@@ -67,7 +67,7 @@ def stream_answer(
67
  "content": (
68
  "You are a helpful visual assistant from Soca AI. Your name is Agus. "
69
  "Please ALWAYS reply in the SAME language as the user's last message! "
70
- "Be concise and specific. Prefer a shorter response for faster generation."
71
  ),
72
  },
73
  {
@@ -133,10 +133,24 @@ def stream_answer(
133
  # =========
134
  CSS = """
135
  #send-wrap { position: relative; }
136
- #send-btn {
137
- position: absolute; right: 10px; bottom: 10px;
138
- min-width: 40px; width: 40px; height: 36px; padding: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  border-radius: 10px;
 
140
  }
141
  """
142
 
@@ -158,16 +172,15 @@ with gr.Blocks(title="Qwen2-VL Visual Assistant", theme=gr.themes.Soft(), css=CS
158
  height=480,
159
  bubble_full_width=False,
160
  )
161
-
162
  with gr.Group(elem_id="send-wrap"):
163
  prompt = gr.Textbox(
164
  label="Prompt",
165
  placeholder="Ask about the image…",
166
- lines=2,
167
  )
168
  send = gr.Button("➤", elem_id="send-btn", variant="primary")
169
 
170
- # Submit on click or on Enter
171
  for trigger in (send.click, prompt.submit):
172
  trigger(
173
  stream_answer,
 
10
  # =======================
11
  # Runtime / model config
12
  # =======================
13
+ DEVICE = "cpu"
14
  DTYPE = torch.float32
15
  MODEL_ID = "Qwen/Qwen2-VL-2B-Instruct"
16
 
 
67
  "content": (
68
  "You are a helpful visual assistant from Soca AI. Your name is Agus. "
69
  "Please ALWAYS reply in the SAME language as the user's last message! "
70
+ "Be concise and specific."
71
  ),
72
  },
73
  {
 
133
  # =========
134
  CSS = """
135
  #send-wrap { position: relative; }
136
+ #send-wrap .gradio-container, #send-wrap .gr-group { position: relative; }
137
+
138
+ /* give the textarea extra right padding so the arrow doesn't overlap text */
139
+ #send-wrap textarea {
140
+ padding-right: 56px !important;
141
+ }
142
+
143
+ /* make the send button float on top, inside the textbox area */
144
+ #send-btn {
145
+ position: absolute;
146
+ right: 12px;
147
+ bottom: 10px;
148
+ min-width: 42px;
149
+ width: 42px;
150
+ height: 36px;
151
+ padding: 0;
152
  border-radius: 10px;
153
+ z-index: 20; /* above the textbox */
154
  }
155
  """
156
 
 
172
  height=480,
173
  bubble_full_width=False,
174
  )
175
+
176
  with gr.Group(elem_id="send-wrap"):
177
  prompt = gr.Textbox(
178
  label="Prompt",
179
  placeholder="Ask about the image…",
180
+ lines=1, # Enter submits
181
  )
182
  send = gr.Button("➤", elem_id="send-btn", variant="primary")
183
 
 
184
  for trigger in (send.click, prompt.submit):
185
  trigger(
186
  stream_answer,