scmlewis commited on
Commit
f026d0c
·
verified ·
1 Parent(s): 00eff89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -11,7 +11,7 @@ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base
11
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
12
  detect_model = YOLO('yolov5s.pt')
13
 
14
- MEMORY_SIZE = 15
15
  last_images = deque([], maxlen=MEMORY_SIZE)
16
  last_captions = deque([], maxlen=MEMORY_SIZE)
17
 
@@ -28,6 +28,19 @@ custom_css = """
28
  font-size: 19px;
29
  margin: 14px 0 22px 0;
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  #generate-btn {
32
  background: linear-gradient(90deg, #31b2fd 0%, #98f972 100%);
33
  color: white;
@@ -79,6 +92,7 @@ def generate_caption(image):
79
  return result_text, gallery
80
 
81
  with gr.Blocks(css=custom_css) as iface:
 
82
  gr.HTML('<div id="app-title">🖼️ Image Captioning with Object Detection</div>')
83
  gr.HTML(
84
  '<div id="instructions">'
@@ -86,14 +100,14 @@ with gr.Blocks(css=custom_css) as iface:
86
  '1️⃣ <b>Upload</b> your image.<br>'
87
  '2️⃣ Click <b>⭐ Generate Caption</b>.<br>'
88
  '3️⃣ View and scroll through your history below.<br>'
89
- '📜 <i>Last 15 results are stored for you.</i>'
90
  '</div>'
91
  )
92
 
93
  image_input = gr.Image(type="pil", label="Upload Image")
94
  generate_btn = gr.Button("⭐ Generate Caption", elem_id="generate-btn")
95
  caption_output = gr.Textbox(label="📝 Caption and Detected Objects", lines=5, interactive=True)
96
- gallery = gr.Gallery(label="Last 15 Images and Captions", scale=3)
97
 
98
  def on_generate(image):
99
  if image is None:
@@ -105,6 +119,7 @@ with gr.Blocks(css=custom_css) as iface:
105
  inputs=image_input,
106
  outputs=[caption_output, gallery]
107
  )
 
108
 
109
  if __name__ == "__main__":
110
  iface.launch()
 
11
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
12
  detect_model = YOLO('yolov5s.pt')
13
 
14
+ MEMORY_SIZE = 10 # Now only 10 in history
15
  last_images = deque([], maxlen=MEMORY_SIZE)
16
  last_captions = deque([], maxlen=MEMORY_SIZE)
17
 
 
28
  font-size: 19px;
29
  margin: 14px 0 22px 0;
30
  }
31
+ /* Responsive + locked max-width */
32
+ #main-app-area {
33
+ max-width: 600px;
34
+ margin-left: auto;
35
+ margin-right: auto;
36
+ padding: 0 8px;
37
+ }
38
+ @media (max-width: 700px) {
39
+ #main-app-area {
40
+ max-width: 98vw;
41
+ padding: 0 2vw;
42
+ }
43
+ }
44
  #generate-btn {
45
  background: linear-gradient(90deg, #31b2fd 0%, #98f972 100%);
46
  color: white;
 
92
  return result_text, gallery
93
 
94
  with gr.Blocks(css=custom_css) as iface:
95
+ gr.HTML('<div id="main-app-area">')
96
  gr.HTML('<div id="app-title">🖼️ Image Captioning with Object Detection</div>')
97
  gr.HTML(
98
  '<div id="instructions">'
 
100
  '1️⃣ <b>Upload</b> your image.<br>'
101
  '2️⃣ Click <b>⭐ Generate Caption</b>.<br>'
102
  '3️⃣ View and scroll through your history below.<br>'
103
+ '📜 <i>Last 10 results are stored for you.</i>'
104
  '</div>'
105
  )
106
 
107
  image_input = gr.Image(type="pil", label="Upload Image")
108
  generate_btn = gr.Button("⭐ Generate Caption", elem_id="generate-btn")
109
  caption_output = gr.Textbox(label="📝 Caption and Detected Objects", lines=5, interactive=True)
110
+ gallery = gr.Gallery(label="Last 10 Images and Captions", scale=3)
111
 
112
  def on_generate(image):
113
  if image is None:
 
119
  inputs=image_input,
120
  outputs=[caption_output, gallery]
121
  )
122
+ gr.HTML('</div>') # end main-app-area
123
 
124
  if __name__ == "__main__":
125
  iface.launch()