Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,11 +81,11 @@ def downsample_video(video_path):
|
|
| 81 |
|
| 82 |
@spaces.GPU(duration=120)
|
| 83 |
def generate_image(model_name: str, text: str, image: Image.Image,
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
"""
|
| 90 |
Generate responses using the selected model for image input.
|
| 91 |
"""
|
|
@@ -137,11 +137,11 @@ def generate_image(model_name: str, text: str, image: Image.Image,
|
|
| 137 |
|
| 138 |
@spaces.GPU
|
| 139 |
def generate_video(model_name: str, text: str, video_path: str,
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
"""
|
| 146 |
Generate responses using the selected model for video input.
|
| 147 |
"""
|
|
@@ -231,47 +231,40 @@ css = """
|
|
| 231 |
border-radius: 10px;
|
| 232 |
padding: 20px;
|
| 233 |
}
|
| 234 |
-
.model-
|
| 235 |
-
background-color: #
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
.model-choices .gr-form:nth-child(3) label {
|
| 240 |
-
background-color: #e0f7fa !important;
|
| 241 |
-
border: 1px solid #00796b !important;
|
| 242 |
-
color: #00796b !important;
|
| 243 |
-
}
|
| 244 |
-
.model-choices .gr-form:nth-child(2) label {
|
| 245 |
-
background-color: #fff3e0 !important;
|
| 246 |
-
border: 1px solid #f57c00 !important;
|
| 247 |
-
color: #f57c00 !important;
|
| 248 |
-
}
|
| 249 |
-
.model-choices .gr-form:nth-child(4) label {
|
| 250 |
-
background-color: #fff3e0 !important;
|
| 251 |
-
border: 1px solid #f57c00 !important;
|
| 252 |
-
color: #f57c00 !important;
|
| 253 |
-
}
|
| 254 |
-
.model-choices .gr-form:nth-child(1) label::after {
|
| 255 |
-
content: " (OCR)";
|
| 256 |
-
font-weight: bold;
|
| 257 |
-
}
|
| 258 |
-
.model-choices .gr-form:nth-child(3) label::after {
|
| 259 |
-
content: " (OCR)";
|
| 260 |
-
font-weight: bold;
|
| 261 |
-
}
|
| 262 |
-
.model-choices .gr-form:nth-child(2) label::after {
|
| 263 |
-
content: " (Reasoning)";
|
| 264 |
-
font-weight: bold;
|
| 265 |
}
|
| 266 |
-
.model-
|
| 267 |
-
|
| 268 |
-
|
|
|
|
|
|
|
| 269 |
}
|
| 270 |
"""
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
# Create the Gradio Interface
|
| 273 |
with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
| 274 |
-
gr.Markdown("#
|
| 275 |
with gr.Row():
|
| 276 |
with gr.Column():
|
| 277 |
with gr.Tabs():
|
|
@@ -291,28 +284,25 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
| 291 |
examples=video_examples,
|
| 292 |
inputs=[video_query, video_upload]
|
| 293 |
)
|
| 294 |
-
|
| 295 |
with gr.Accordion("Advanced options", open=False):
|
| 296 |
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
|
| 297 |
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6)
|
| 298 |
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9)
|
| 299 |
top_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50)
|
| 300 |
repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2)
|
| 301 |
-
|
| 302 |
with gr.Column():
|
| 303 |
with gr.Column(elem_classes="canvas-output"):
|
| 304 |
gr.Markdown("## Output")
|
| 305 |
output = gr.Textbox(label="Raw Output Stream", interactive=False, lines=2)
|
| 306 |
with gr.Accordion("(Result.md)", open=False):
|
| 307 |
markdown_output = gr.Markdown(label="(Result.md)")
|
| 308 |
-
|
| 309 |
model_choice = gr.Radio(
|
| 310 |
choices=["Camel-Doc-OCR-062825", "GLM-4.1V-9B-Thinking", "Megalodon-OCR-Sync-0713", "ViLaSR-7B"],
|
| 311 |
label="Select Model",
|
| 312 |
-
value="Camel-Doc-OCR-062825"
|
| 313 |
-
elem_classes="model-choices"
|
| 314 |
)
|
| 315 |
gr.Markdown("**Model Info 💻** | [Report Bug](https://huggingface.co/spaces/prithivMLmods/Multimodal-VLM-v1.0/discussions)")
|
|
|
|
| 316 |
|
| 317 |
# Define the submit button actions
|
| 318 |
image_submit.click(fn=generate_image,
|
|
|
|
| 81 |
|
| 82 |
@spaces.GPU(duration=120)
|
| 83 |
def generate_image(model_name: str, text: str, image: Image.Image,
|
| 84 |
+
max_new_tokens: int = 1024,
|
| 85 |
+
temperature: float = 0.6,
|
| 86 |
+
top_p: float = 0.9,
|
| 87 |
+
top_k: int = 50,
|
| 88 |
+
repetition_penalty: float = 1.2):
|
| 89 |
"""
|
| 90 |
Generate responses using the selected model for image input.
|
| 91 |
"""
|
|
|
|
| 137 |
|
| 138 |
@spaces.GPU
|
| 139 |
def generate_video(model_name: str, text: str, video_path: str,
|
| 140 |
+
max_new_tokens: int = 1024,
|
| 141 |
+
temperature: float = 0.6,
|
| 142 |
+
top_p: float = 0.9,
|
| 143 |
+
top_k: int = 50,
|
| 144 |
+
repetition_penalty: float = 1.2):
|
| 145 |
"""
|
| 146 |
Generate responses using the selected model for video input.
|
| 147 |
"""
|
|
|
|
| 231 |
border-radius: 10px;
|
| 232 |
padding: 20px;
|
| 233 |
}
|
| 234 |
+
.model-choice-reasoning {
|
| 235 |
+
background-color: #2ecc71 !important; /* Green for reasoning models */
|
| 236 |
+
color: white !important;
|
| 237 |
+
padding: 5px 10px;
|
| 238 |
+
border-radius: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
}
|
| 240 |
+
.model-choice-ocr {
|
| 241 |
+
background-color: #3498db !important; /* Blue for OCR models */
|
| 242 |
+
color: white !important;
|
| 243 |
+
padding: 5px 10px;
|
| 244 |
+
border-radius: 5px;
|
| 245 |
}
|
| 246 |
"""
|
| 247 |
|
| 248 |
+
# JavaScript to apply classes to radio button labels
|
| 249 |
+
js_script = """
|
| 250 |
+
<script>
|
| 251 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 252 |
+
const labels = document.querySelectorAll('.gr-radio label');
|
| 253 |
+
labels.forEach(label => {
|
| 254 |
+
const text = label.textContent.trim();
|
| 255 |
+
if (text === 'GLM-4.1V-9B-Thinking' || text === 'ViLaSR-7B') {
|
| 256 |
+
label.classList.add('model-choice-reasoning');
|
| 257 |
+
} else if (text === 'Camel-Doc-OCR-062825' || text === 'Megalodon-OCR-Sync-0713') {
|
| 258 |
+
label.classList.add('model-choice-ocr');
|
| 259 |
+
}
|
| 260 |
+
});
|
| 261 |
+
});
|
| 262 |
+
</script>
|
| 263 |
+
"""
|
| 264 |
+
|
| 265 |
# Create the Gradio Interface
|
| 266 |
with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
| 267 |
+
gr.Markdown("# Multimodal VLM v1.0")
|
| 268 |
with gr.Row():
|
| 269 |
with gr.Column():
|
| 270 |
with gr.Tabs():
|
|
|
|
| 284 |
examples=video_examples,
|
| 285 |
inputs=[video_query, video_upload]
|
| 286 |
)
|
|
|
|
| 287 |
with gr.Accordion("Advanced options", open=False):
|
| 288 |
max_new_tokens = gr.Slider(label="Max new tokens", minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
|
| 289 |
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=4.0, step=0.1, value=0.6)
|
| 290 |
top_p = gr.Slider(label="Top-p (nucleus sampling)", minimum=0.05, maximum=1.0, step=0.05, value=0.9)
|
| 291 |
top_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=50)
|
| 292 |
repetition_penalty = gr.Slider(label="Repetition penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.2)
|
|
|
|
| 293 |
with gr.Column():
|
| 294 |
with gr.Column(elem_classes="canvas-output"):
|
| 295 |
gr.Markdown("## Output")
|
| 296 |
output = gr.Textbox(label="Raw Output Stream", interactive=False, lines=2)
|
| 297 |
with gr.Accordion("(Result.md)", open=False):
|
| 298 |
markdown_output = gr.Markdown(label="(Result.md)")
|
|
|
|
| 299 |
model_choice = gr.Radio(
|
| 300 |
choices=["Camel-Doc-OCR-062825", "GLM-4.1V-9B-Thinking", "Megalodon-OCR-Sync-0713", "ViLaSR-7B"],
|
| 301 |
label="Select Model",
|
| 302 |
+
value="Camel-Doc-OCR-062825"
|
|
|
|
| 303 |
)
|
| 304 |
gr.Markdown("**Model Info 💻** | [Report Bug](https://huggingface.co/spaces/prithivMLmods/Multimodal-VLM-v1.0/discussions)")
|
| 305 |
+
gr.HTML(js_script) # Inject JavaScript to apply classes
|
| 306 |
|
| 307 |
# Define the submit button actions
|
| 308 |
image_submit.click(fn=generate_image,
|