Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,28 +27,35 @@ from gradio.themes.utils import colors, fonts, sizes
|
|
| 27 |
|
| 28 |
# --- Theme and CSS Definition ---
|
| 29 |
|
| 30 |
-
# Define the
|
| 31 |
-
colors.
|
| 32 |
-
name="
|
| 33 |
-
c50="#
|
| 34 |
-
c100="#
|
| 35 |
-
c200="#
|
| 36 |
-
c300="#
|
| 37 |
-
c400="#
|
| 38 |
-
c500="#
|
| 39 |
-
c600="#
|
| 40 |
-
c700="#
|
| 41 |
-
c800="#
|
| 42 |
-
c900="#
|
| 43 |
-
c950="#
|
| 44 |
)
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
def __init__(
|
| 48 |
self,
|
| 49 |
*,
|
| 50 |
primary_hue: colors.Color | str = colors.gray,
|
| 51 |
-
secondary_hue: colors.Color | str = colors.
|
| 52 |
neutral_hue: colors.Color | str = colors.slate,
|
| 53 |
text_size: sizes.Size | str = sizes.text_lg,
|
| 54 |
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
|
@@ -67,17 +74,88 @@ class SpringGreenTheme(Soft):
|
|
| 67 |
font_mono=font_mono,
|
| 68 |
)
|
| 69 |
super().set(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
button_primary_background_fill="linear-gradient(90deg, *secondary_400, *secondary_500)",
|
| 71 |
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
block_title_text_weight="600",
|
| 75 |
-
block_border_width="
|
| 76 |
block_shadow="*shadow_drop_lg",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
)
|
| 78 |
|
| 79 |
# Instantiate the new theme
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Constants for text generation
|
| 83 |
MAX_MAX_NEW_TOKENS = 2048
|
|
@@ -312,24 +390,8 @@ video_examples = [
|
|
| 312 |
["Identify the main actions in the cartoon video.", "videos/2.mp4"]
|
| 313 |
]
|
| 314 |
|
| 315 |
-
css = """
|
| 316 |
-
#main-title h1 {
|
| 317 |
-
font-size: 2.3em !important;
|
| 318 |
-
}
|
| 319 |
-
#output-title h2 {
|
| 320 |
-
font-size: 2.1em !important;
|
| 321 |
-
}
|
| 322 |
-
.submit-btn {
|
| 323 |
-
background-color: #2980b9 !important;
|
| 324 |
-
color: white !important;
|
| 325 |
-
}
|
| 326 |
-
.submit-btn:hover {
|
| 327 |
-
background-color: #3498db !important;
|
| 328 |
-
}
|
| 329 |
-
"""
|
| 330 |
-
|
| 331 |
# Create the Gradio Interface
|
| 332 |
-
with gr.Blocks(css=css, theme=
|
| 333 |
gr.Markdown("# **Multimodal OCR**", elem_id="main-title")
|
| 334 |
with gr.Row():
|
| 335 |
with gr.Column(scale=2):
|
|
@@ -337,7 +399,7 @@ with gr.Blocks(css=css, theme=spring_green_theme) as demo:
|
|
| 337 |
with gr.TabItem("Image Inference"):
|
| 338 |
image_query = gr.Textbox(label="Query Input", placeholder="Enter your query here...")
|
| 339 |
image_upload = gr.Image(type="pil", label="Upload Image", height=290)
|
| 340 |
-
image_submit = gr.Button("Submit", variant="primary"
|
| 341 |
gr.Examples(
|
| 342 |
examples=image_examples,
|
| 343 |
inputs=[image_query, image_upload]
|
|
@@ -345,7 +407,7 @@ with gr.Blocks(css=css, theme=spring_green_theme) as demo:
|
|
| 345 |
with gr.TabItem("Video Inference"):
|
| 346 |
video_query = gr.Textbox(label="Query Input", placeholder="Enter your query here...")
|
| 347 |
video_upload = gr.Video(label="Upload Video", height=290)
|
| 348 |
-
video_submit = gr.Button("Submit", variant="primary"
|
| 349 |
gr.Examples(
|
| 350 |
examples=video_examples,
|
| 351 |
inputs=[video_query, video_upload]
|
|
|
|
| 27 |
|
| 28 |
# --- Theme and CSS Definition ---
|
| 29 |
|
| 30 |
+
# Define the Thistle color palette
|
| 31 |
+
colors.thistle = colors.Color(
|
| 32 |
+
name="thistle",
|
| 33 |
+
c50="#F9F5F9",
|
| 34 |
+
c100="#F0E8F1",
|
| 35 |
+
c200="#E7DBE8",
|
| 36 |
+
c300="#DECEE0",
|
| 37 |
+
c400="#D2BFD8",
|
| 38 |
+
c500="#D8BFD8", # Thistle base color
|
| 39 |
+
c600="#B59CB7",
|
| 40 |
+
c700="#927996",
|
| 41 |
+
c800="#6F5675",
|
| 42 |
+
c900="#4C3454",
|
| 43 |
+
c950="#291233",
|
| 44 |
)
|
| 45 |
|
| 46 |
+
colors.red_gray = colors.Color(
|
| 47 |
+
name="red_gray",
|
| 48 |
+
c50="#f7eded", c100="#f5dcdc", c200="#efb4b4", c300="#e78f8f",
|
| 49 |
+
c400="#d96a6a", c500="#c65353", c600="#b24444", c700="#8f3434",
|
| 50 |
+
c800="#732d2d", c900="#5f2626", c950="#4d2020",
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
class ThistleTheme(Soft):
|
| 54 |
def __init__(
|
| 55 |
self,
|
| 56 |
*,
|
| 57 |
primary_hue: colors.Color | str = colors.gray,
|
| 58 |
+
secondary_hue: colors.Color | str = colors.thistle, # Use the new color
|
| 59 |
neutral_hue: colors.Color | str = colors.slate,
|
| 60 |
text_size: sizes.Size | str = sizes.text_lg,
|
| 61 |
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
|
|
|
| 74 |
font_mono=font_mono,
|
| 75 |
)
|
| 76 |
super().set(
|
| 77 |
+
background_fill_primary="*primary_50",
|
| 78 |
+
background_fill_primary_dark="*primary_900",
|
| 79 |
+
body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)",
|
| 80 |
+
body_background_fill_dark="linear-gradient(135deg, *primary_900, *primary_800)",
|
| 81 |
+
button_primary_text_color="black",
|
| 82 |
+
button_primary_text_color_hover="white",
|
| 83 |
button_primary_background_fill="linear-gradient(90deg, *secondary_400, *secondary_500)",
|
| 84 |
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 85 |
+
button_primary_background_fill_dark="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 86 |
+
button_primary_background_fill_hover_dark="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 87 |
+
button_secondary_text_color="black",
|
| 88 |
+
button_secondary_text_color_hover="white",
|
| 89 |
+
button_secondary_background_fill="linear-gradient(90deg, *primary_300, *primary_300)",
|
| 90 |
+
button_secondary_background_fill_hover="linear-gradient(90deg, *primary_400, *primary_400)",
|
| 91 |
+
button_secondary_background_fill_dark="linear-gradient(90deg, *primary_500, *primary_600)",
|
| 92 |
+
button_secondary_background_fill_hover_dark="linear-gradient(90deg, *primary_500, *primary_500)",
|
| 93 |
+
slider_color="*secondary_400",
|
| 94 |
+
slider_color_dark="*secondary_600",
|
| 95 |
block_title_text_weight="600",
|
| 96 |
+
block_border_width="3px",
|
| 97 |
block_shadow="*shadow_drop_lg",
|
| 98 |
+
button_primary_shadow="*shadow_drop_lg",
|
| 99 |
+
button_large_padding="11px",
|
| 100 |
+
color_accent_soft="*primary_100",
|
| 101 |
+
block_label_background_fill="*primary_200",
|
| 102 |
)
|
| 103 |
|
| 104 |
# Instantiate the new theme
|
| 105 |
+
thistle_theme = ThistleTheme()
|
| 106 |
+
|
| 107 |
+
css = """
|
| 108 |
+
#main-title h1 {
|
| 109 |
+
font-size: 2.3em !important;
|
| 110 |
+
}
|
| 111 |
+
#output-title h2 {
|
| 112 |
+
font-size: 2.1em !important;
|
| 113 |
+
}
|
| 114 |
+
:root {
|
| 115 |
+
--color-grey-50: #f9fafb;
|
| 116 |
+
--banner-background: var(--secondary-400);
|
| 117 |
+
--banner-text-color: var(--primary-100);
|
| 118 |
+
--banner-background-dark: var(--secondary-800);
|
| 119 |
+
--banner-text-color-dark: var(--primary-100);
|
| 120 |
+
--banner-chrome-height: calc(16px + 43px);
|
| 121 |
+
--chat-chrome-height-wide-no-banner: 320px;
|
| 122 |
+
--chat-chrome-height-narrow-no-banner: 450px;
|
| 123 |
+
--chat-chrome-height-wide: calc(var(--chat-chrome-height-wide-no-banner) + var(--banner-chrome-height));
|
| 124 |
+
--chat-chrome-height-narrow: calc(var(--chat-chrome-height-narrow-no-banner) + var(--banner-chrome-height));
|
| 125 |
+
}
|
| 126 |
+
.banner-message { background-color: var(--banner-background); padding: 5px; margin: 0; border-radius: 5px; border: none; }
|
| 127 |
+
.banner-message-text { font-size: 13px; font-weight: bolder; color: var(--banner-text-color) !important; }
|
| 128 |
+
body.dark .banner-message { background-color: var(--banner-background-dark) !important; }
|
| 129 |
+
body.dark .gradio-container .contain .banner-message .banner-message-text { color: var(--banner-text-color-dark) !important; }
|
| 130 |
+
.toast-body { background-color: var(--color-grey-50); }
|
| 131 |
+
.html-container:has(.css-styles) { padding: 0; margin: 0; }
|
| 132 |
+
.css-styles { height: 0; }
|
| 133 |
+
.model-message { text-align: end; }
|
| 134 |
+
.model-dropdown-container { display: flex; align-items: center; gap: 10px; padding: 0; }
|
| 135 |
+
.user-input-container .multimodal-textbox{ border: none !important; }
|
| 136 |
+
.control-button { height: 51px; }
|
| 137 |
+
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); }
|
| 138 |
+
button.cancel:hover, .cancel[disabled] { background: var(--button-cancel-background-fill-hover); color: var(--button-cancel-text-color-hover); }
|
| 139 |
+
.opt-out-message { top: 8px; }
|
| 140 |
+
.opt-out-message .html-container, .opt-out-checkbox label { font-size: 14px !important; padding: 0 !important; margin: 0 !important; color: var(--neutral-400) !important; }
|
| 141 |
+
div.block.chatbot { height: calc(100svh - var(--chat-chrome-height-wide)) !important; max-height: 900px !important; }
|
| 142 |
+
div.no-padding { padding: 0 !important; }
|
| 143 |
+
@media (max-width: 1280px) { div.block.chatbot { height: calc(100svh - var(--chat-chrome-height-wide)) !important; } }
|
| 144 |
+
@media (max-width: 1024px) {
|
| 145 |
+
.responsive-row { flex-direction: column; }
|
| 146 |
+
.model-message { text-align: start; font-size: 10px !important; }
|
| 147 |
+
.model-dropdown-container { flex-direction: column; align-items: flex-start; }
|
| 148 |
+
div.block.chatbot { height: calc(100svh - var(--chat-chrome-height-narrow)) !important; }
|
| 149 |
+
}
|
| 150 |
+
@media (max-width: 400px) {
|
| 151 |
+
.responsive-row { flex-direction: column; }
|
| 152 |
+
.model-message { text-align: start; font-size: 10px !important; }
|
| 153 |
+
.model-dropdown-container { flex-direction: column; align-items: flex-start; }
|
| 154 |
+
div.block.chatbot { max-height: 360px !important; }
|
| 155 |
+
}
|
| 156 |
+
@media (max-height: 932px) { .chatbot { max-height: 500px !important; } }
|
| 157 |
+
@media (max-height: 1280px) { div.block.chatbot { max-height: 800px !important; } }
|
| 158 |
+
"""
|
| 159 |
|
| 160 |
# Constants for text generation
|
| 161 |
MAX_MAX_NEW_TOKENS = 2048
|
|
|
|
| 390 |
["Identify the main actions in the cartoon video.", "videos/2.mp4"]
|
| 391 |
]
|
| 392 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
# Create the Gradio Interface
|
| 394 |
+
with gr.Blocks(css=css, theme=thistle_theme) as demo:
|
| 395 |
gr.Markdown("# **Multimodal OCR**", elem_id="main-title")
|
| 396 |
with gr.Row():
|
| 397 |
with gr.Column(scale=2):
|
|
|
|
| 399 |
with gr.TabItem("Image Inference"):
|
| 400 |
image_query = gr.Textbox(label="Query Input", placeholder="Enter your query here...")
|
| 401 |
image_upload = gr.Image(type="pil", label="Upload Image", height=290)
|
| 402 |
+
image_submit = gr.Button("Submit", variant="primary")
|
| 403 |
gr.Examples(
|
| 404 |
examples=image_examples,
|
| 405 |
inputs=[image_query, image_upload]
|
|
|
|
| 407 |
with gr.TabItem("Video Inference"):
|
| 408 |
video_query = gr.Textbox(label="Query Input", placeholder="Enter your query here...")
|
| 409 |
video_upload = gr.Video(label="Upload Video", height=290)
|
| 410 |
+
video_submit = gr.Button("Submit", variant="primary")
|
| 411 |
gr.Examples(
|
| 412 |
examples=video_examples,
|
| 413 |
inputs=[video_query, video_upload]
|