Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ from transformers import Qwen2_5_VLForConditionalGeneration
|
|
18 |
def progress_bar_html(label: str, primary_color: str = "#4B0082", secondary_color: str = "#9370DB") -> str:
|
19 |
"""
|
20 |
Returns an HTML snippet for a thin animated progress bar with a label.
|
21 |
-
Colors can be customized; default colors are used for Qwen2VL/Aya
|
22 |
"""
|
23 |
return f'''
|
24 |
<div style="display: flex; align-items: center;">
|
@@ -37,7 +37,7 @@ def progress_bar_html(label: str, primary_color: str = "#4B0082", secondary_colo
|
|
37 |
|
38 |
def downsample_video(video_path):
|
39 |
"""
|
40 |
-
Downsamples a video file by extracting
|
41 |
Returns a list of tuples (PIL.Image, timestamp).
|
42 |
"""
|
43 |
vidcap = cv2.VideoCapture(video_path)
|
@@ -132,23 +132,14 @@ def model_inference(input_dict, history, use_rolmocr=False):
|
|
132 |
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
|
133 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
134 |
thread.start()
|
135 |
-
|
136 |
buffer = ""
|
137 |
yield progress_bar_html(f"Processing with {model_name}")
|
138 |
-
|
139 |
-
# Stream generation
|
140 |
for new_text in streamer:
|
141 |
-
buffer += new_text
|
|
|
142 |
time.sleep(0.01)
|
143 |
yield buffer
|
144 |
|
145 |
-
# Once complete, save to response.txt and yield final confirmation
|
146 |
-
with open("response.txt", "w", encoding="utf-8") as f:
|
147 |
-
f.write(buffer)
|
148 |
-
|
149 |
-
yield f"\n✅ Response saved to `response.txt`:\n\n{buffer}"
|
150 |
-
return
|
151 |
-
|
152 |
# Gradio Interface
|
153 |
examples = [
|
154 |
[{"text": "OCR the Text in the Image", "files": ["rolm/1.jpeg"]}],
|
@@ -172,5 +163,4 @@ demo = gr.ChatInterface(
|
|
172 |
additional_inputs=[gr.Checkbox(label="Use RolmOCR", value=False, info="Check to use RolmOCR, uncheck to use Qwen2VL OCR")],
|
173 |
)
|
174 |
|
175 |
-
|
176 |
-
demo.launch(debug=True)
|
|
|
18 |
def progress_bar_html(label: str, primary_color: str = "#4B0082", secondary_color: str = "#9370DB") -> str:
|
19 |
"""
|
20 |
Returns an HTML snippet for a thin animated progress bar with a label.
|
21 |
+
Colors can be customized; default colors are used for Qwen2VL/Aya‑Vision.
|
22 |
"""
|
23 |
return f'''
|
24 |
<div style="display: flex; align-items: center;">
|
|
|
37 |
|
38 |
def downsample_video(video_path):
|
39 |
"""
|
40 |
+
Downsamples a video file by extracting 10 evenly spaced frames.
|
41 |
Returns a list of tuples (PIL.Image, timestamp).
|
42 |
"""
|
43 |
vidcap = cv2.VideoCapture(video_path)
|
|
|
132 |
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
|
133 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
134 |
thread.start()
|
|
|
135 |
buffer = ""
|
136 |
yield progress_bar_html(f"Processing with {model_name}")
|
|
|
|
|
137 |
for new_text in streamer:
|
138 |
+
buffer += new_text
|
139 |
+
buffer = buffer.replace("<|im_end|>", "")
|
140 |
time.sleep(0.01)
|
141 |
yield buffer
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
# Gradio Interface
|
144 |
examples = [
|
145 |
[{"text": "OCR the Text in the Image", "files": ["rolm/1.jpeg"]}],
|
|
|
163 |
additional_inputs=[gr.Checkbox(label="Use RolmOCR", value=False, info="Check to use RolmOCR, uncheck to use Qwen2VL OCR")],
|
164 |
)
|
165 |
|
166 |
+
demo.launch(debug=True, ssr_mode=False)
|
|