Spaces:
Sleeping
Sleeping
add interface logic
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image, ImageDraw, ImageFont
|
4 |
-
import requests
|
5 |
from transformers import AutoProcessor
|
6 |
from modeling_florence2 import Florence2ForConditionalGeneration
|
7 |
from configuration_florence2 import Florence2Config
|
@@ -79,6 +78,7 @@ def process_image(image, task):
|
|
79 |
|
80 |
return parsed_answer
|
81 |
|
|
|
82 |
def main_process(image, task):
|
83 |
result = process_image(image, task)
|
84 |
|
@@ -88,12 +88,12 @@ def main_process(image, task):
|
|
88 |
else:
|
89 |
fig = plot_bbox(image, result[TASK_PROMPTS[task]])
|
90 |
output_image = fig_to_pil(fig)
|
91 |
-
return output_image, None
|
92 |
else:
|
93 |
-
return None, str(result)
|
94 |
|
95 |
def reset_outputs():
|
96 |
-
return None, None
|
97 |
|
98 |
with gr.Blocks(title="Florence-2 Demo") as iface:
|
99 |
gr.Markdown("# Florence-2 Demo")
|
@@ -110,23 +110,16 @@ with gr.Blocks(title="Florence-2 Demo") as iface:
|
|
110 |
output_image = gr.Image(label="Processed Image", visible=False)
|
111 |
output_text = gr.Textbox(label="Output", visible=False)
|
112 |
|
113 |
-
def process_and_show(image, task):
|
114 |
-
img_output, text_output = main_process(image, task)
|
115 |
-
if img_output is not None:
|
116 |
-
return {output_image: gr.update(value=img_output, visible=True), output_text: gr.update(visible=False)}
|
117 |
-
else:
|
118 |
-
return {output_image: gr.update(visible=False), output_text: gr.update(value=text_output, visible=True)}
|
119 |
-
|
120 |
submit_button.click(
|
121 |
-
fn=
|
122 |
inputs=[image_input, task_dropdown],
|
123 |
-
outputs=[output_image, output_text]
|
124 |
)
|
125 |
|
126 |
reset_button.click(
|
127 |
fn=reset_outputs,
|
128 |
inputs=[],
|
129 |
-
outputs=[output_image, output_text]
|
130 |
)
|
131 |
|
132 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image, ImageDraw, ImageFont
|
|
|
4 |
from transformers import AutoProcessor
|
5 |
from modeling_florence2 import Florence2ForConditionalGeneration
|
6 |
from configuration_florence2 import Florence2Config
|
|
|
78 |
|
79 |
return parsed_answer
|
80 |
|
81 |
+
|
82 |
def main_process(image, task):
|
83 |
result = process_image(image, task)
|
84 |
|
|
|
88 |
else:
|
89 |
fig = plot_bbox(image, result[TASK_PROMPTS[task]])
|
90 |
output_image = fig_to_pil(fig)
|
91 |
+
return output_image, gr.update(visible=True), None, gr.update(visible=False)
|
92 |
else:
|
93 |
+
return None, gr.update(visible=False), str(result), gr.update(visible=True)
|
94 |
|
95 |
def reset_outputs():
|
96 |
+
return None, gr.update(visible=False), None, gr.update(visible=False)
|
97 |
|
98 |
with gr.Blocks(title="Florence-2 Demo") as iface:
|
99 |
gr.Markdown("# Florence-2 Demo")
|
|
|
110 |
output_image = gr.Image(label="Processed Image", visible=False)
|
111 |
output_text = gr.Textbox(label="Output", visible=False)
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
submit_button.click(
|
114 |
+
fn=main_process,
|
115 |
inputs=[image_input, task_dropdown],
|
116 |
+
outputs=[output_image, output_image, output_text, output_text]
|
117 |
)
|
118 |
|
119 |
reset_button.click(
|
120 |
fn=reset_outputs,
|
121 |
inputs=[],
|
122 |
+
outputs=[output_image, output_image, output_text, output_text]
|
123 |
)
|
124 |
|
125 |
iface.launch()
|