Spaces:
Sleeping
Sleeping
Create module_vision.py
Browse files- module_vision.py +36 -0
module_vision.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: module_vision.py
|
3 |
+
Description: A module for chat using image + text with a multimodal interface.
|
4 |
+
Author: Didier Guillevic
|
5 |
+
Date: 2025-05-08
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
import vlm
|
10 |
+
|
11 |
+
def process(message, history):
|
12 |
+
"""Generate the model response given message and history
|
13 |
+
"""
|
14 |
+
messages = vlm.build_messages(message, history)
|
15 |
+
yield from vlm.stream_response(messages)
|
16 |
+
|
17 |
+
#examples=[
|
18 |
+
# [{"text": "What is happening in the video?", "files": ["Usain_Bolt_floats_to_victory.mp4"]}],
|
19 |
+
# [{"text": "Pourrais-tu décrire cette image?", "files": ["le_monde_2025-04-01.jpg"]}],
|
20 |
+
# [{"text": "Could you descrive the video?", "files": ["threads_brittlestar_post_DIABZcnJ.mp4"]}],
|
21 |
+
#]
|
22 |
+
|
23 |
+
#
|
24 |
+
# User interface
|
25 |
+
#
|
26 |
+
with gr.Blocks() as demo:
|
27 |
+
chat_interface = gr.ChatInterface(
|
28 |
+
fn=process,
|
29 |
+
description="Chat with text / text+image / text+video.",
|
30 |
+
#examples=examples,
|
31 |
+
#cache_examples=False,
|
32 |
+
stop_btn="Stop Generation",
|
33 |
+
multimodal=True,
|
34 |
+
type="messages"
|
35 |
+
)
|
36 |
+
|