Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -47,6 +47,7 @@ model_m = Qwen2VLForConditionalGeneration.from_pretrained(
|
|
47 |
torch_dtype=torch.float16
|
48 |
).to("cuda").eval()
|
49 |
|
|
|
50 |
def clean_chat_history(chat_history):
|
51 |
"""
|
52 |
Filter out any chat entries whose "content" is not a string.
|
@@ -58,6 +59,7 @@ def clean_chat_history(chat_history):
|
|
58 |
cleaned.append(msg)
|
59 |
return cleaned
|
60 |
|
|
|
61 |
def downsample_video(video_path):
|
62 |
"""
|
63 |
Downsamples the video to 10 evenly spaced frames.
|
@@ -80,6 +82,7 @@ def downsample_video(video_path):
|
|
80 |
vidcap.release()
|
81 |
return frames
|
82 |
|
|
|
83 |
def progress_bar_html(label: str) -> str:
|
84 |
"""
|
85 |
Returns an HTML snippet for a thin progress bar with a label.
|
@@ -100,6 +103,7 @@ def progress_bar_html(label: str) -> str:
|
|
100 |
</style>
|
101 |
'''
|
102 |
|
|
|
103 |
@spaces.GPU(duration=60, enable_queue=True)
|
104 |
def generate(input_dict: dict, chat_history: list[dict],
|
105 |
max_new_tokens: int = 1024,
|
@@ -222,6 +226,200 @@ def generate(input_dict: dict, chat_history: list[dict],
|
|
222 |
final_response = "".join(outputs)
|
223 |
yield final_response
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
demo = gr.ChatInterface(
|
226 |
fn=generate,
|
227 |
additional_inputs=[
|
@@ -237,6 +435,7 @@ demo = gr.ChatInterface(
|
|
237 |
textbox=gr.MultimodalTextbox(label="Query Input", file_types=["image", "video"], file_count="multiple"),
|
238 |
stop_btn="Stop Generation",
|
239 |
multimodal=True,
|
|
|
240 |
)
|
241 |
|
242 |
if __name__ == "__main__":
|
|
|
47 |
torch_dtype=torch.float16
|
48 |
).to("cuda").eval()
|
49 |
|
50 |
+
|
51 |
def clean_chat_history(chat_history):
|
52 |
"""
|
53 |
Filter out any chat entries whose "content" is not a string.
|
|
|
59 |
cleaned.append(msg)
|
60 |
return cleaned
|
61 |
|
62 |
+
|
63 |
def downsample_video(video_path):
|
64 |
"""
|
65 |
Downsamples the video to 10 evenly spaced frames.
|
|
|
82 |
vidcap.release()
|
83 |
return frames
|
84 |
|
85 |
+
|
86 |
def progress_bar_html(label: str) -> str:
|
87 |
"""
|
88 |
Returns an HTML snippet for a thin progress bar with a label.
|
|
|
103 |
</style>
|
104 |
'''
|
105 |
|
106 |
+
|
107 |
@spaces.GPU(duration=60, enable_queue=True)
|
108 |
def generate(input_dict: dict, chat_history: list[dict],
|
109 |
max_new_tokens: int = 1024,
|
|
|
226 |
final_response = "".join(outputs)
|
227 |
yield final_response
|
228 |
|
229 |
+
|
230 |
+
# Custom CSS for the theme (combining font and global styles)
|
231 |
+
custom_css = """
|
232 |
+
/* ------------------ START FONTS.CSS ------------------ */
|
233 |
+
/* GT Maru Regular */
|
234 |
+
@font-face {
|
235 |
+
font-family: 'GT-Maru';
|
236 |
+
src: url('/fonts/GT Maru/GT-Maru-Regular.otf') format('opentype');
|
237 |
+
font-weight: 400;
|
238 |
+
font-style: normal;
|
239 |
+
font-display: swap;
|
240 |
+
}
|
241 |
+
@font-face {
|
242 |
+
font-family: 'GT-Maru';
|
243 |
+
src: url('/fonts/GT Maru/GT-Maru-Regular-Oblique.otf') format('opentype');
|
244 |
+
font-weight: 400;
|
245 |
+
font-style: italic;
|
246 |
+
font-display: swap;
|
247 |
+
}
|
248 |
+
|
249 |
+
/* GT Maru Light */
|
250 |
+
@font-face {
|
251 |
+
font-family: 'GT-Maru';
|
252 |
+
src: url('/fonts/GT Maru/GT-Maru-Light.otf') format('opentype');
|
253 |
+
font-weight: 300;
|
254 |
+
font-style: normal;
|
255 |
+
font-display: swap;
|
256 |
+
}
|
257 |
+
@font-face {
|
258 |
+
font-family: 'GT-Maru';
|
259 |
+
src: url('/fonts/GT Maru/GT-Maru-Light-Oblique.otf') format('opentype');
|
260 |
+
font-weight: 300;
|
261 |
+
font-style: italic;
|
262 |
+
font-display: swap;
|
263 |
+
}
|
264 |
+
|
265 |
+
/* GT Maru Medium */
|
266 |
+
@font-face {
|
267 |
+
font-family: 'GT-Maru';
|
268 |
+
src: url('/fonts/GT Maru/GT-Maru-Medium.otf') format('opentype');
|
269 |
+
font-weight: 500;
|
270 |
+
font-style: normal;
|
271 |
+
font-display: swap;
|
272 |
+
}
|
273 |
+
@font-face {
|
274 |
+
font-family: 'GT-Maru';
|
275 |
+
src: url('/fonts/GT Maru/GT-Maru-Medium-Oblique.otf') format('opentype');
|
276 |
+
font-weight: 500;
|
277 |
+
font-style: italic;
|
278 |
+
font-display: swap;
|
279 |
+
}
|
280 |
+
|
281 |
+
/* GT Maru Bold */
|
282 |
+
@font-face {
|
283 |
+
font-family: 'GT-Maru';
|
284 |
+
src: url('/fonts/GT Maru/GT-Maru-Bold.otf') format('opentype');
|
285 |
+
font-weight: 700;
|
286 |
+
font-style: normal;
|
287 |
+
font-display: swap;
|
288 |
+
}
|
289 |
+
@font-face {
|
290 |
+
font-family: 'GT-Maru';
|
291 |
+
src: url('/fonts/GT Maru/GT-Maru-Bold-Oblique.otf') format('opentype');
|
292 |
+
font-weight: 700;
|
293 |
+
font-style: italic;
|
294 |
+
font-display: swap;
|
295 |
+
}
|
296 |
+
|
297 |
+
/* GT Maru Black */
|
298 |
+
@font-face {
|
299 |
+
font-family: 'GT-Maru';
|
300 |
+
src: url('/fonts/GT Maru/GT-Maru-Black.otf') format('opentype');
|
301 |
+
font-weight: 900;
|
302 |
+
font-style: normal;
|
303 |
+
font-display: swap;
|
304 |
+
}
|
305 |
+
@font-face {
|
306 |
+
font-family: 'GT-Maru';
|
307 |
+
src: url('/fonts/GT Maru/GT-Maru-Black-Oblique.otf') format('opentype');
|
308 |
+
font-weight: 900;
|
309 |
+
font-style: italic;
|
310 |
+
font-display: swap;
|
311 |
+
}
|
312 |
+
|
313 |
+
/* GT Maru Mono Regular */
|
314 |
+
@font-face {
|
315 |
+
font-family: 'GT-Maru-Mono';
|
316 |
+
src: url('/fonts/GT Maru/GT-Maru-Mono-Regular.otf') format('opentype');
|
317 |
+
font-weight: 400;
|
318 |
+
font-style: normal;
|
319 |
+
font-display: swap;
|
320 |
+
}
|
321 |
+
@font-face {
|
322 |
+
font-family: 'GT-Maru-Mono';
|
323 |
+
src: url('/fonts/GT Maru/GT-Maru-Mono-Regular-Oblique.otf') format('opentype');
|
324 |
+
font-weight: 400;
|
325 |
+
font-style: italic;
|
326 |
+
font-display: swap;
|
327 |
+
}
|
328 |
+
|
329 |
+
/* GT Maru Mono Medium */
|
330 |
+
@font-face {
|
331 |
+
font-family: 'GT-Maru-Mono';
|
332 |
+
src: url('/fonts/GT Maru/GT-Maru-Mono-Medium.otf') format('opentype');
|
333 |
+
font-weight: 500;
|
334 |
+
font-style: normal;
|
335 |
+
font-display: swap;
|
336 |
+
}
|
337 |
+
@font-face {
|
338 |
+
font-family: 'GT-Maru-Mono';
|
339 |
+
src: url('/fonts/GT Maru/GT-Maru-Mono-Medium-Oblique.otf') format('opentype');
|
340 |
+
font-weight: 500;
|
341 |
+
font-style: italic;
|
342 |
+
font-display: swap;
|
343 |
+
}
|
344 |
+
|
345 |
+
/* GT Maru Mega Midi (for special display text) */
|
346 |
+
@font-face {
|
347 |
+
font-family: 'GT-Maru-Mega-Midi';
|
348 |
+
src: url('/fonts/GT Maru/GT-Maru-Mega-Midi.otf') format('opentype');
|
349 |
+
font-weight: normal;
|
350 |
+
font-style: normal;
|
351 |
+
font-display: swap;
|
352 |
+
}
|
353 |
+
|
354 |
+
/* ------------------ END FONTS.CSS ------------------ */
|
355 |
+
/* ------------------ START GLOBAL.CSS ------------------ */
|
356 |
+
|
357 |
+
@import "tailwindcss";
|
358 |
+
|
359 |
+
:root {
|
360 |
+
--background: #ffffff;
|
361 |
+
--foreground: #171717;
|
362 |
+
--font-gt-maru: 'GT-Maru', sans-serif;
|
363 |
+
--font-gt-maru-mono: 'GT-Maru-Mono', monospace;
|
364 |
+
--font-gt-maru-mega: 'GT-Maru-Mega-Midi', sans-serif;
|
365 |
+
--notebook-bg: #f3f4f6; /* Tailwind gray-100 */
|
366 |
+
--notebook-dot: #d1d5db; /* Tailwind gray-300 for dots */
|
367 |
+
}
|
368 |
+
|
369 |
+
@theme inline {
|
370 |
+
--color-background: var(--background);
|
371 |
+
--color-foreground: var(--foreground);
|
372 |
+
--font-sans: var(--font-gt-maru);
|
373 |
+
--font-mono: var(--font-gt-maru-mono);
|
374 |
+
}
|
375 |
+
|
376 |
+
@media (prefers-color-scheme: dark) {
|
377 |
+
:root {
|
378 |
+
--background: #0a0a0a;
|
379 |
+
--foreground: #ededed;
|
380 |
+
}
|
381 |
+
}
|
382 |
+
|
383 |
+
body {
|
384 |
+
color: var(--foreground);
|
385 |
+
font-family: var(--font-gt-maru);
|
386 |
+
background-color: var(--notebook-bg);
|
387 |
+
background-image: radial-gradient(var(--notebook-dot) 1px, transparent 1px);
|
388 |
+
background-size: 24px 24px;
|
389 |
+
}
|
390 |
+
|
391 |
+
/* Container styling for paper effect */
|
392 |
+
.paper-container {
|
393 |
+
background-color: rgba(255, 255, 255, 0.7);
|
394 |
+
border-radius: 12px;
|
395 |
+
box-shadow:
|
396 |
+
0 2px 8px rgba(0, 0, 0, 0.05),
|
397 |
+
0 8px 20px rgba(0, 0, 0, 0.03);
|
398 |
+
backdrop-filter: blur(2px);
|
399 |
+
}
|
400 |
+
|
401 |
+
/* Notebook paper dotted background - now for specific elements only */
|
402 |
+
.notebook-paper-bg {
|
403 |
+
background-color: var(--notebook-bg);
|
404 |
+
background-image: radial-gradient(var(--notebook-dot) 1px, transparent 1px);
|
405 |
+
background-size: 24px 24px;
|
406 |
+
background-position: 0 0;
|
407 |
+
border-radius: 12px;
|
408 |
+
box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.03);
|
409 |
+
}
|
410 |
+
|
411 |
+
/* Shadow effect for paper depth */
|
412 |
+
.paper-shadow {
|
413 |
+
box-shadow:
|
414 |
+
0 1px 3px rgba(0, 0, 0, 0.05),
|
415 |
+
0 4px 6px rgba(0, 0, 0, 0.03),
|
416 |
+
inset 0 0 3px rgba(255, 255, 255, 0.8);
|
417 |
+
}
|
418 |
+
|
419 |
+
/* ------------------ END GLOBAL.CSS ------------------ */
|
420 |
+
"""
|
421 |
+
|
422 |
+
# Create the Gradio ChatInterface with the custom CSS applied
|
423 |
demo = gr.ChatInterface(
|
424 |
fn=generate,
|
425 |
additional_inputs=[
|
|
|
435 |
textbox=gr.MultimodalTextbox(label="Query Input", file_types=["image", "video"], file_count="multiple"),
|
436 |
stop_btn="Stop Generation",
|
437 |
multimodal=True,
|
438 |
+
css=custom_css # Apply our custom theme CSS
|
439 |
)
|
440 |
|
441 |
if __name__ == "__main__":
|