Spaces:
Running
on
Zero
Running
on
Zero
update app
Browse files
app.py
CHANGED
|
@@ -32,35 +32,29 @@ from gradio.themes.utils import colors, fonts, sizes
|
|
| 32 |
|
| 33 |
# --- Theme and CSS Definition ---
|
| 34 |
|
| 35 |
-
# Define the
|
| 36 |
-
colors.
|
| 37 |
-
name="
|
| 38 |
-
c50="#
|
| 39 |
-
c100="#
|
| 40 |
-
c200="#
|
| 41 |
-
c300="#
|
| 42 |
-
c400="#
|
| 43 |
-
c500="#
|
| 44 |
-
c600="#
|
| 45 |
-
c700="#
|
| 46 |
-
c800="#
|
| 47 |
-
c900="#
|
| 48 |
-
c950="#
|
| 49 |
)
|
| 50 |
|
| 51 |
-
colors.red_gray = colors.Color(
|
| 52 |
-
name="red_gray",
|
| 53 |
-
c50="#f7eded", c100="#f5dcdc", c200="#efb4b4", c300="#e78f8f",
|
| 54 |
-
c400="#d96a6a", c500="#c65353", c600="#b24444", c700="#8f3434",
|
| 55 |
-
c800="#732d2d", c900="#5f2626", c950="#4d2020",
|
| 56 |
-
)
|
| 57 |
|
| 58 |
-
class
|
| 59 |
def __init__(
|
| 60 |
self,
|
| 61 |
*,
|
| 62 |
primary_hue: colors.Color | str = colors.gray,
|
| 63 |
-
secondary_hue: colors.Color | str = colors.
|
| 64 |
neutral_hue: colors.Color | str = colors.slate,
|
| 65 |
text_size: sizes.Size | str = sizes.text_lg,
|
| 66 |
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
|
@@ -83,19 +77,13 @@ class ThistleTheme(Soft):
|
|
| 83 |
background_fill_primary_dark="*primary_900",
|
| 84 |
body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
|
| 85 |
body_background_fill_dark="linear-gradient(135deg, *primary_900, *primary_800)",
|
| 86 |
-
button_primary_text_color="
|
| 87 |
button_primary_text_color_hover="white",
|
| 88 |
-
button_primary_background_fill="linear-gradient(90deg, *
|
| 89 |
-
button_primary_background_fill_hover="linear-gradient(90deg, *
|
| 90 |
button_primary_background_fill_dark="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 91 |
button_primary_background_fill_hover_dark="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 92 |
-
|
| 93 |
-
button_secondary_text_color_hover="white",
|
| 94 |
-
button_secondary_background_fill="linear-gradient(90deg, *primary_300, *primary_300)",
|
| 95 |
-
button_secondary_background_fill_hover="linear-gradient(90deg, *primary_400, *primary_400)",
|
| 96 |
-
button_secondary_background_fill_dark="linear-gradient(90deg, *primary_500, *primary_600)",
|
| 97 |
-
button_secondary_background_fill_hover_dark="linear-gradient(90deg, *primary_500, *primary_500)",
|
| 98 |
-
slider_color="*secondary_400",
|
| 99 |
slider_color_dark="*secondary_600",
|
| 100 |
block_title_text_weight="600",
|
| 101 |
block_border_width="3px",
|
|
@@ -107,7 +95,7 @@ class ThistleTheme(Soft):
|
|
| 107 |
)
|
| 108 |
|
| 109 |
# Instantiate the new theme
|
| 110 |
-
|
| 111 |
|
| 112 |
css = """
|
| 113 |
#main-title h1 {
|
|
@@ -116,55 +104,13 @@ css = """
|
|
| 116 |
#output-title h2 {
|
| 117 |
font-size: 2.1em !important;
|
| 118 |
}
|
| 119 |
-
:root {
|
| 120 |
-
--color-grey-50: #f9fafb;
|
| 121 |
-
--banner-background: var(--secondary-400);
|
| 122 |
-
--banner-text-color: var(--primary-100);
|
| 123 |
-
--banner-background-dark: var(--secondary-800);
|
| 124 |
-
--banner-text-color-dark: var(--primary-100);
|
| 125 |
-
--banner-chrome-height: calc(16px + 43px);
|
| 126 |
-
--chat-chrome-height-wide-no-banner: 320px;
|
| 127 |
-
--chat-chrome-height-narrow-no-banner: 450px;
|
| 128 |
-
--chat-chrome-height-wide: calc(var(--chat-chrome-height-wide-no-banner) + var(--banner-chrome-height));
|
| 129 |
-
--chat-chrome-height-narrow: calc(var(--chat-chrome-height-narrow-no-banner) + var(--banner-chrome-height));
|
| 130 |
-
}
|
| 131 |
-
.banner-message { background-color: var(--banner-background); padding: 5px; margin: 0; border-radius: 5px; border: none; }
|
| 132 |
-
.banner-message-text { font-size: 13px; font-weight: bolder; color: var(--banner-text-color) !important; }
|
| 133 |
-
body.dark .banner-message { background-color: var(--banner-background-dark) !important; }
|
| 134 |
-
body.dark .gradio-container .contain .banner-message .banner-message-text { color: var(--banner-text-color-dark) !important; }
|
| 135 |
-
.toast-body { background-color: var(--color-grey-50); }
|
| 136 |
-
.html-container:has(.css-styles) { padding: 0; margin: 0; }
|
| 137 |
-
.css-styles { height: 0; }
|
| 138 |
-
.model-message { text-align: end; }
|
| 139 |
-
.model-dropdown-container { display: flex; align-items: center; gap: 10px; padding: 0; }
|
| 140 |
-
.user-input-container .multimodal-textbox{ border: none !important; }
|
| 141 |
-
.control-button { height: 51px; }
|
| 142 |
-
button.cancel { border: var(--button-border-width) solid var(--button-cancel-border-color); background: var(--button-cancel-background-fill); color: var(--button-cancel-text-color); box-shadow: var(--button-cancel-shadow); }
|
| 143 |
-
button.cancel:hover, .cancel[disabled] { background: var(--button-cancel-background-fill-hover); color: var(--button-cancel-text-color-hover); }
|
| 144 |
-
.opt-out-message { top: 8px; }
|
| 145 |
-
.opt-out-message .html-container, .opt-out-checkbox label { font-size: 14px !important; padding: 0 !important; margin: 0 !important; color: var(--neutral-400) !important; }
|
| 146 |
-
div.block.chatbot { height: calc(100svh - var(--chat-chrome-height-wide)) !important; max-height: 900px !important; }
|
| 147 |
-
div.no-padding { padding: 0 !important; }
|
| 148 |
-
@media (max-width: 1280px) { div.block.chatbot { height: calc(100svh - var(--chat-chrome-height-wide)) !important; } }
|
| 149 |
-
@media (max-width: 1024px) {
|
| 150 |
-
.responsive-row { flex-direction: column; }
|
| 151 |
-
.model-message { text-align: start; font-size: 10px !important; }
|
| 152 |
-
.model-dropdown-container { flex-direction: column; align-items: flex-start; }
|
| 153 |
-
div.block.chatbot { height: calc(100svh - var(--chat-chrome-height-narrow)) !important; }
|
| 154 |
-
}
|
| 155 |
-
@media (max-width: 400px) {
|
| 156 |
-
.responsive-row { flex-direction: column; }
|
| 157 |
-
.model-message { text-align: start; font-size: 10px !important; }
|
| 158 |
-
.model-dropdown-container { flex-direction: column; align-items: flex-start; }
|
| 159 |
-
div.block.chatbot { max-height: 360px !important; }
|
| 160 |
-
}
|
| 161 |
-
@media (max-height: 932px) { .chatbot { max-height: 500px !important; } }
|
| 162 |
-
@media (max-height: 1280px) { div.block.chatbot { max-height: 800px !important; } }
|
| 163 |
"""
|
| 164 |
|
| 165 |
|
| 166 |
# --- Constants and Model Setup ---
|
| 167 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
|
|
|
|
|
|
| 168 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 169 |
|
| 170 |
print("--- System Information ---")
|
|
@@ -404,7 +350,7 @@ def process_document_stream(
|
|
| 404 |
def create_gradio_interface():
|
| 405 |
"""Builds and returns the Gradio web interface."""
|
| 406 |
|
| 407 |
-
with gr.Blocks(theme=
|
| 408 |
gr.Markdown("# **Multimodal VLM v1.0**", elem_id="main-title")
|
| 409 |
gr.Markdown("Explore the capabilities of various Vision Language Models for tasks like OCR, VQA, and Object Detection.")
|
| 410 |
|
|
@@ -412,28 +358,27 @@ def create_gradio_interface():
|
|
| 412 |
# --- TAB 1: Document and General VLMs ---
|
| 413 |
with gr.TabItem("📄 Document & General VLM"):
|
| 414 |
with gr.Row():
|
| 415 |
-
with gr.Column(scale=
|
| 416 |
-
#gr.Markdown("### 1. Configure Inputs")
|
| 417 |
model_choice = gr.Dropdown(
|
| 418 |
choices=["Camel-Doc-OCR-062825 (OCR)", "GLM-4.1V-9B (Thinking)"],
|
| 419 |
label="Select Model", value= "Camel-Doc-OCR-062825 (OCR)"
|
| 420 |
)
|
| 421 |
-
image_input_doc = gr.Image(label="Upload Image", type="pil", sources=['upload'], height=
|
| 422 |
prompt_input_doc = gr.Textbox(label="Query Input", placeholder="e.g., 'Transcribe the text in this document.'")
|
| 423 |
|
| 424 |
-
with gr.Accordion("Advanced
|
| 425 |
-
max_new_tokens = gr.Slider(minimum=
|
| 426 |
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.7)
|
| 427 |
top_p = gr.Slider(label="Top-p", minimum=0.1, maximum=1.0, step=0.05, value=0.9)
|
| 428 |
-
top_k = gr.Slider(label="Top-k", minimum=1, maximum=
|
| 429 |
repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.1)
|
| 430 |
|
| 431 |
-
|
| 432 |
-
|
|
|
|
| 433 |
|
| 434 |
-
with gr.Column(scale=
|
| 435 |
gr.Markdown("## Output", elem_id="output-title")
|
| 436 |
-
#with gr.Tab("Output Stream"):
|
| 437 |
output_stream = gr.Textbox(label="Raw Output Stream", interactive=False, lines=24, show_copy_button=True)
|
| 438 |
|
| 439 |
gr.Examples(
|
|
|
|
| 32 |
|
| 33 |
# --- Theme and CSS Definition ---
|
| 34 |
|
| 35 |
+
# Define the SteelBlue color palette
|
| 36 |
+
colors.steel_blue = colors.Color(
|
| 37 |
+
name="steel_blue",
|
| 38 |
+
c50="#EBF3F8",
|
| 39 |
+
c100="#D3E5F0",
|
| 40 |
+
c200="#A8CCE1",
|
| 41 |
+
c300="#7DB3D2",
|
| 42 |
+
c400="#529AC3",
|
| 43 |
+
c500="#4682B4", # SteelBlue base color
|
| 44 |
+
c600="#3E72A0",
|
| 45 |
+
c700="#36638C",
|
| 46 |
+
c800="#2E5378",
|
| 47 |
+
c900="#264364",
|
| 48 |
+
c950="#1E3450",
|
| 49 |
)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
class SteelBlueTheme(Soft):
|
| 53 |
def __init__(
|
| 54 |
self,
|
| 55 |
*,
|
| 56 |
primary_hue: colors.Color | str = colors.gray,
|
| 57 |
+
secondary_hue: colors.Color | str = colors.steel_blue,
|
| 58 |
neutral_hue: colors.Color | str = colors.slate,
|
| 59 |
text_size: sizes.Size | str = sizes.text_lg,
|
| 60 |
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
|
|
|
| 77 |
background_fill_primary_dark="*primary_900",
|
| 78 |
body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
|
| 79 |
body_background_fill_dark="linear-gradient(135deg, *primary_900, *primary_800)",
|
| 80 |
+
button_primary_text_color="white",
|
| 81 |
button_primary_text_color_hover="white",
|
| 82 |
+
button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 83 |
+
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 84 |
button_primary_background_fill_dark="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 85 |
button_primary_background_fill_hover_dark="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 86 |
+
slider_color="*secondary_500",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
slider_color_dark="*secondary_600",
|
| 88 |
block_title_text_weight="600",
|
| 89 |
block_border_width="3px",
|
|
|
|
| 95 |
)
|
| 96 |
|
| 97 |
# Instantiate the new theme
|
| 98 |
+
steel_blue_theme = SteelBlueTheme()
|
| 99 |
|
| 100 |
css = """
|
| 101 |
#main-title h1 {
|
|
|
|
| 104 |
#output-title h2 {
|
| 105 |
font-size: 2.1em !important;
|
| 106 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
"""
|
| 108 |
|
| 109 |
|
| 110 |
# --- Constants and Model Setup ---
|
| 111 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
| 112 |
+
MAX_MAX_NEW_TOKENS = 4096
|
| 113 |
+
DEFAULT_MAX_NEW_TOKENS = 2048
|
| 114 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 115 |
|
| 116 |
print("--- System Information ---")
|
|
|
|
| 350 |
def create_gradio_interface():
|
| 351 |
"""Builds and returns the Gradio web interface."""
|
| 352 |
|
| 353 |
+
with gr.Blocks(theme=steel_blue_theme, css=css) as demo:
|
| 354 |
gr.Markdown("# **Multimodal VLM v1.0**", elem_id="main-title")
|
| 355 |
gr.Markdown("Explore the capabilities of various Vision Language Models for tasks like OCR, VQA, and Object Detection.")
|
| 356 |
|
|
|
|
| 358 |
# --- TAB 1: Document and General VLMs ---
|
| 359 |
with gr.TabItem("📄 Document & General VLM"):
|
| 360 |
with gr.Row():
|
| 361 |
+
with gr.Column(scale=2):
|
|
|
|
| 362 |
model_choice = gr.Dropdown(
|
| 363 |
choices=["Camel-Doc-OCR-062825 (OCR)", "GLM-4.1V-9B (Thinking)"],
|
| 364 |
label="Select Model", value= "Camel-Doc-OCR-062825 (OCR)"
|
| 365 |
)
|
| 366 |
+
image_input_doc = gr.Image(label="Upload Image", type="pil", sources=['upload'], height=290)
|
| 367 |
prompt_input_doc = gr.Textbox(label="Query Input", placeholder="e.g., 'Transcribe the text in this document.'")
|
| 368 |
|
| 369 |
+
with gr.Accordion("Advanced options", open=False):
|
| 370 |
+
max_new_tokens = gr.Slider(minimum=1, maximum=MAX_MAX_NEW_TOKENS, value=DEFAULT_MAX_NEW_TOKENS, step=1, label="Max New Tokens")
|
| 371 |
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.7)
|
| 372 |
top_p = gr.Slider(label="Top-p", minimum=0.1, maximum=1.0, step=0.05, value=0.9)
|
| 373 |
+
top_k = gr.Slider(label="Top-k", minimum=1, maximum=1000, step=1, value=40)
|
| 374 |
repetition_penalty = gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.1)
|
| 375 |
|
| 376 |
+
with gr.Row():
|
| 377 |
+
process_btn = gr.Button("Submit", variant="primary")
|
| 378 |
+
clear_btn = gr.Button("Clear", variant="secondary")
|
| 379 |
|
| 380 |
+
with gr.Column(scale=3):
|
| 381 |
gr.Markdown("## Output", elem_id="output-title")
|
|
|
|
| 382 |
output_stream = gr.Textbox(label="Raw Output Stream", interactive=False, lines=24, show_copy_button=True)
|
| 383 |
|
| 384 |
gr.Examples(
|