Spaces:
Running
Running
Latest Changes
Browse files- ui/layout.py +69 -45
- ui/styles.py +18 -9
ui/layout.py
CHANGED
|
@@ -14,54 +14,78 @@ def build_ui(model, processor):
|
|
| 14 |
style=style
|
| 15 |
)
|
| 16 |
|
| 17 |
-
with gr.Blocks(
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"Generate captions or explanations from images using a CPU-only BLIP model."
|
| 22 |
-
)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
)
|
| 43 |
-
output_text = gr.Textbox(
|
| 44 |
-
label="Generated Output",
|
| 45 |
-
lines=5
|
| 46 |
-
)
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
["./assets/marriage.jpg", "Creative Caption"],
|
| 55 |
-
["./assets/giraffe.jpg", "Short Caption"]
|
| 56 |
-
],
|
| 57 |
-
inputs=[image_input, style_select]
|
| 58 |
-
)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
return demo
|
|
|
|
| 14 |
style=style
|
| 15 |
)
|
| 16 |
|
| 17 |
+
with gr.Blocks(
|
| 18 |
+
title="BLIP Image Captioning (Zero-GPU)",
|
| 19 |
+
fill_height=True
|
| 20 |
+
) as demo:
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
gr.Markdown("## 🖼️ BLIP Image Captioning (Zero-GPU)")
|
| 23 |
+
gr.Markdown(
|
| 24 |
+
"Generate captions or explanations from images using a CPU-only BLIP model."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# -----------------------------
|
| 28 |
+
# MAIN FIXED LAYOUT
|
| 29 |
+
# -----------------------------
|
| 30 |
+
with gr.Row(equal_height=True):
|
| 31 |
+
|
| 32 |
+
# LEFT: Image Column (Fixed)
|
| 33 |
+
with gr.Column(scale=1, min_width=420):
|
| 34 |
+
image_input = gr.Image(
|
| 35 |
+
type="pil",
|
| 36 |
+
label="Upload Image",
|
| 37 |
+
height=420,
|
| 38 |
+
elem_id="image-box"
|
| 39 |
+
)
|
| 40 |
+
generate_btn = gr.Button(
|
| 41 |
+
"Generate",
|
| 42 |
+
variant="primary"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# RIGHT: Controls + Output (Fixed)
|
| 46 |
+
with gr.Column(scale=1, min_width=420):
|
| 47 |
|
| 48 |
+
style_select = gr.Dropdown(
|
| 49 |
+
choices=[
|
| 50 |
+
"Short Caption",
|
| 51 |
+
"Detailed Caption",
|
| 52 |
+
"Creative Caption",
|
| 53 |
+
"Image Explanation"
|
| 54 |
+
],
|
| 55 |
+
value="Detailed Caption",
|
| 56 |
+
label="Caption Style"
|
| 57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
output_text = gr.Textbox(
|
| 60 |
+
label="Generated Output",
|
| 61 |
+
lines=6,
|
| 62 |
+
max_lines=8,
|
| 63 |
+
elem_id="output-box"
|
| 64 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# -----------------------------
|
| 67 |
+
# EXAMPLES (SEPARATE SECTION)
|
| 68 |
+
# -----------------------------
|
| 69 |
+
gr.Markdown("### Examples")
|
| 70 |
+
|
| 71 |
+
gr.Examples(
|
| 72 |
+
examples=[
|
| 73 |
+
["./assets/zebra.jpg", "Detailed Caption"],
|
| 74 |
+
["./assets/cat.jpg", "Image Explanation"],
|
| 75 |
+
["./assets/fridge.jpg", "Detailed Caption"],
|
| 76 |
+
["./assets/marriage.jpg", "Creative Caption"],
|
| 77 |
+
["./assets/giraffe.jpg", "Short Caption"]
|
| 78 |
+
],
|
| 79 |
+
inputs=[image_input, style_select]
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
# -----------------------------
|
| 83 |
+
# EVENT
|
| 84 |
+
# -----------------------------
|
| 85 |
+
generate_btn.click(
|
| 86 |
+
fn=run_caption,
|
| 87 |
+
inputs=[image_input, style_select],
|
| 88 |
+
outputs=output_text
|
| 89 |
+
)
|
| 90 |
|
| 91 |
return demo
|
ui/styles.py
CHANGED
|
@@ -1,16 +1,25 @@
|
|
| 1 |
CSS_STYLE = """
|
| 2 |
-
#
|
| 3 |
-
max-
|
| 4 |
-
margin: auto;
|
| 5 |
}
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
"""
|
|
|
|
| 1 |
CSS_STYLE = """
|
| 2 |
+
#image-box {
|
| 3 |
+
max-height: 420px;
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
+
#image-box img {
|
| 7 |
+
object-fit: contain;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
#output-box textarea {
|
| 11 |
+
min-height: 180px;
|
| 12 |
+
max-height: 240px;
|
| 13 |
}
|
| 14 |
|
| 15 |
+
.gradio-container {
|
| 16 |
+
max-width: 1100px !important;
|
| 17 |
+
margin: auto;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
@media (max-width: 900px) {
|
| 21 |
+
.gradio-container {
|
| 22 |
+
padding: 12px;
|
| 23 |
+
}
|
| 24 |
}
|
| 25 |
"""
|