Chris Addis commited on
Commit ·
00c2f37
1
Parent(s): c477cef
Matcha 2
Browse files
app.py
CHANGED
|
@@ -72,27 +72,26 @@ def get_base_filename(filepath):
|
|
| 72 |
|
| 73 |
# Define the Gradio interface
|
| 74 |
def create_demo():
|
|
|
|
| 75 |
custom_css = """
|
| 76 |
/* Container for the image component (#current-image-display is the elem_id of gr.Image) */
|
| 77 |
#current-image-display {
|
| 78 |
height: 600px; /* Define container height */
|
| 79 |
-
width:
|
| 80 |
display: flex; /* Use flexbox for alignment */
|
| 81 |
justify-content: center; /* Center content horizontally */
|
| 82 |
align-items: center; /* Center content vertically */
|
| 83 |
overflow: hidden; /* Hide any potential overflow from container */
|
| 84 |
}
|
| 85 |
|
| 86 |
-
/*
|
| 87 |
-
#current-image-display img
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
width: auto !important;
|
| 95 |
-
height: auto !important;
|
| 96 |
}
|
| 97 |
"""
|
| 98 |
# --- Pass css to gr.Blocks ---
|
|
@@ -153,9 +152,8 @@ def create_demo():
|
|
| 153 |
with gr.Column(scale=2):
|
| 154 |
current_image = gr.Image(
|
| 155 |
label="Current Image",
|
| 156 |
-
height=600,
|
| 157 |
type="filepath",
|
| 158 |
-
elem_id="current-image-display",
|
| 159 |
show_fullscreen_button=True,
|
| 160 |
show_download_button=False,
|
| 161 |
show_share_button=False,
|
|
@@ -211,6 +209,10 @@ def create_demo():
|
|
| 211 |
prompt0 = prompt_new()
|
| 212 |
model_name = model_choice
|
| 213 |
client_to_use = OR # Default client
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
result = client_to_use.generate_caption(
|
| 216 |
img, model=model_name, max_image_size=512,
|
|
|
|
| 72 |
|
| 73 |
# Define the Gradio interface
|
| 74 |
def create_demo():
|
| 75 |
+
# --- Reintroduce CSS ---
|
| 76 |
custom_css = """
|
| 77 |
/* Container for the image component (#current-image-display is the elem_id of gr.Image) */
|
| 78 |
#current-image-display {
|
| 79 |
height: 600px; /* Define container height */
|
| 80 |
+
width: 100%; /* Define container width (takes column width) */
|
| 81 |
display: flex; /* Use flexbox for alignment */
|
| 82 |
justify-content: center; /* Center content horizontally */
|
| 83 |
align-items: center; /* Center content vertically */
|
| 84 |
overflow: hidden; /* Hide any potential overflow from container */
|
| 85 |
}
|
| 86 |
|
| 87 |
+
/* The actual <img> element inside the container */
|
| 88 |
+
#current-image-display img {
|
| 89 |
+
object-fit: contain; /* Scale keeping aspect ratio, within bounds */
|
| 90 |
+
max-width: 100%; /* Prevent image exceeding container width */
|
| 91 |
+
max-height: 100%; /* Prevent image exceeding container height */
|
| 92 |
+
width: auto; /* Use natural width unless constrained by max-width */
|
| 93 |
+
height: auto; /* Use natural height unless constrained by max-height */
|
| 94 |
+
display: block; /* Ensure image behaves predictably in flex */
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
"""
|
| 97 |
# --- Pass css to gr.Blocks ---
|
|
|
|
| 152 |
with gr.Column(scale=2):
|
| 153 |
current_image = gr.Image(
|
| 154 |
label="Current Image",
|
|
|
|
| 155 |
type="filepath",
|
| 156 |
+
elem_id="current-image-display", # ADDED - for CSS targeting
|
| 157 |
show_fullscreen_button=True,
|
| 158 |
show_download_button=False,
|
| 159 |
show_share_button=False,
|
|
|
|
| 209 |
prompt0 = prompt_new()
|
| 210 |
model_name = model_choice
|
| 211 |
client_to_use = OR # Default client
|
| 212 |
+
# Add logic here if you need to switch between OR and gemini clients based on model_name
|
| 213 |
+
# Example:
|
| 214 |
+
# if model_name.startswith("google/gemini") and gemini:
|
| 215 |
+
# client_to_use = gemini
|
| 216 |
|
| 217 |
result = client_to_use.generate_caption(
|
| 218 |
img, model=model_name, max_image_size=512,
|