HF-Pawan commited on
Commit
8a690b3
·
1 Parent(s): 01e8e77

Latest Changes

Browse files
Files changed (2) hide show
  1. ui/layout.py +69 -45
  2. 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(title="BLIP Image Captioning (Zero-GPU)") as demo:
18
- with gr.Column(elem_id="container"):
19
- gr.Markdown("## 🖼️ BLIP Image Captioning (Zero-GPU)")
20
- gr.Markdown(
21
- "Generate captions or explanations from images using a CPU-only BLIP model."
22
- )
23
 
24
- with gr.Row(equal_height=True):
25
- with gr.Column():
26
- image_input = gr.Image(
27
- type="pil",
28
- label="Upload Image"
29
- )
30
- generate_btn = gr.Button("Generate")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- with gr.Column():
33
- style_select = gr.Dropdown(
34
- choices=[
35
- "Short Caption",
36
- "Detailed Caption",
37
- "Creative Caption",
38
- "Image Explanation"
39
- ],
40
- value="Detailed Caption",
41
- label="Caption Style"
42
- )
43
- output_text = gr.Textbox(
44
- label="Generated Output",
45
- lines=5
46
- )
47
 
48
- # Examples preload inputs ONLY
49
- gr.Examples(
50
- examples=[
51
- ["./assets/zebra.jpg", "Detailed Caption"],
52
- ["./assets/cat.jpg", "Image Explanation"],
53
- ["./assets/fridge.jpg", "Detailed Caption"],
54
- ["./assets/marriage.jpg", "Creative Caption"],
55
- ["./assets/giraffe.jpg", "Short Caption"]
56
- ],
57
- inputs=[image_input, style_select]
58
- )
59
 
60
- # ✅ Single source of inference
61
- generate_btn.click(
62
- fn=run_caption,
63
- inputs=[image_input, style_select],
64
- outputs=output_text
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
- #container {
3
- max-width: 1280px;
4
- margin: auto;
5
  }
6
 
7
- @media (min-width: 1600px) {
8
- #container {
9
- max-width: 1440px;
10
- }
 
 
 
11
  }
12
 
13
- #title h1 {
14
- font-size: 2.4em !important;
 
 
 
 
 
 
 
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
  """