de-Rodrigo commited on
Commit
cc83f63
Β·
1 Parent(s): 32862dd

Gradio Visual Improvements

Browse files
Files changed (1) hide show
  1. app.py +60 -61
app.py CHANGED
@@ -134,71 +134,70 @@ if __name__ == "__main__":
134
  with gr.Blocks() as demo:
135
  gr.Markdown("# Saliency Maps with the MERIT Dataset πŸŽ’πŸ“ƒπŸ†")
136
 
137
- gr.Image(value=README_IMAGE_PATH, width=800, height=600)
138
-
139
- with gr.Tab("Introduction"):
140
- gr.Markdown(
141
- """
142
- ## Welcome to Saliency Maps with the [MERIT Dataset](https://huggingface.co/datasets/de-Rodrigo/merit) πŸŽ’πŸ“ƒπŸ†
143
-
144
- This space demonstrates the capabilities of different Vision Language models
145
- for document understanding tasks.
146
-
147
- ### Key Features:
148
- - Process images from the [MERIT Dataset](https://huggingface.co/datasets/de-Rodrigo/merit) or upload your own image.
149
- - Use a fine-tuned version of the models availabe to extract grades from documents.
150
- - Visualize saliency maps to understand where the model is looking (WIP πŸ› οΈ).
151
- """
152
- )
153
-
154
- gr.Image(
155
- value=GIF_PATH,
156
- label="Dataset samples you can process",
157
- width=800,
158
- height=600,
159
- )
160
-
161
- with gr.Tab("Try It Yourself"):
162
- gr.Markdown(
163
- "Select a model and an image from the dataset, or upload your own image."
164
- )
165
-
166
- with gr.Row():
167
- with gr.Column():
168
- model_dropdown = gr.Dropdown(choices=models, label="Select Model")
169
- dataset_slider = gr.Slider(
170
- minimum=0,
171
- maximum=len(dataset) - 1,
172
- step=1,
173
- label="Dataset Image Index",
174
- )
175
- upload_image = gr.Image(
176
- type="pil", label="Or Upload Your Own Image"
177
  )
178
 
179
- preview_image = gr.Image(label="Selected/Uploaded Image")
180
-
181
- process_button = gr.Button("Process Image")
182
-
183
- with gr.Row():
184
- output_image = gr.Image(label="Processed Image")
185
- output_text = gr.Textbox(label="Result")
186
 
187
- # Update preview image when slider changes
188
- dataset_slider.change(
189
- fn=update_image, inputs=[dataset_slider], outputs=[preview_image]
190
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
- # Update preview image when an image is uploaded
193
- upload_image.change(
194
- fn=lambda x: x, inputs=[upload_image], outputs=[preview_image]
195
- )
196
 
197
- # Process image when button is clicked
198
- process_button.click(
199
- fn=process_image,
200
- inputs=[model_dropdown, upload_image, dataset_slider],
201
- outputs=[output_image, output_text],
202
- )
203
 
204
  demo.launch()
 
134
  with gr.Blocks() as demo:
135
  gr.Markdown("# Saliency Maps with the MERIT Dataset πŸŽ’πŸ“ƒπŸ†")
136
 
137
+ with gr.Column(scale=2, min_width=600):
138
+ gr.Image(value=README_IMAGE_PATH, height=400, fit="scale-down")
139
+
140
+ with gr.Tabs():
141
+ with gr.Tab("Introduction"):
142
+ gr.Markdown(
143
+ """
144
+ ## Welcome to Saliency Maps with the [MERIT Dataset](https://huggingface.co/datasets/de-Rodrigo/merit) πŸŽ’πŸ“ƒπŸ†
145
+
146
+ This space demonstrates the capabilities of different Vision Language models
147
+ for document understanding tasks.
148
+
149
+ ### Key Features:
150
+ - Process images from the [MERIT Dataset](https://huggingface.co/datasets/de-Rodrigo/merit) or upload your own image.
151
+ - Use a fine-tuned version of the models availabe to extract grades from documents.
152
+ - Visualize saliency maps to understand where the model is looking (WIP πŸ› οΈ).
153
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  )
155
 
156
+ with gr.Tab("Try It Yourself"):
157
+ gr.Markdown(
158
+ "Select a model and an image from the dataset, or upload your own image."
159
+ )
 
 
 
160
 
161
+ with gr.Row():
162
+ with gr.Column():
163
+ model_dropdown = gr.Dropdown(
164
+ choices=models, label="Select Model"
165
+ )
166
+ dataset_slider = gr.Slider(
167
+ minimum=0,
168
+ maximum=len(dataset) - 1,
169
+ step=1,
170
+ label="Dataset Image Index",
171
+ )
172
+ upload_image = gr.Image(
173
+ type="pil", label="Or Upload Your Own Image"
174
+ )
175
+
176
+ preview_image = gr.Image(label="Selected/Uploaded Image")
177
+
178
+ process_button = gr.Button("Process Image")
179
+
180
+ with gr.Row():
181
+ output_image = gr.Image(label="Processed Image")
182
+ output_text = gr.Textbox(label="Result")
183
+
184
+ # Update preview image when slider changes
185
+ dataset_slider.change(
186
+ fn=update_image,
187
+ inputs=[dataset_slider],
188
+ outputs=[preview_image],
189
+ )
190
 
191
+ # Update preview image when an image is uploaded
192
+ upload_image.change(
193
+ fn=lambda x: x, inputs=[upload_image], outputs=[preview_image]
194
+ )
195
 
196
+ # Process image when button is clicked
197
+ process_button.click(
198
+ fn=process_image,
199
+ inputs=[model_dropdown, upload_image, dataset_slider],
200
+ outputs=[output_image, output_text],
201
+ )
202
 
203
  demo.launch()