Spaces:
Runtime error
Runtime error
wip
Browse files
app.py
CHANGED
|
@@ -52,8 +52,8 @@ OCR_WITH_REGION_EXAMPLES = [
|
|
| 52 |
["microsoft/Florence-2-large-ft", OCR_WITH_REGION_TASK_NAME, "https://media.roboflow.com/inference/license_plate_1.jpg"]
|
| 53 |
]
|
| 54 |
|
| 55 |
-
|
| 56 |
-
DEVICE = "cuda"
|
| 57 |
MODELS, PROCESSORS = load_models(DEVICE)
|
| 58 |
|
| 59 |
|
|
@@ -74,10 +74,6 @@ def process(checkpoint_dropdown, task_dropdown, image_input):
|
|
| 74 |
return response[task]
|
| 75 |
|
| 76 |
|
| 77 |
-
image_output_component = None
|
| 78 |
-
text_output_component = None
|
| 79 |
-
|
| 80 |
-
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
gr.Markdown(MARKDOWN)
|
| 83 |
with gr.Row():
|
|
@@ -96,80 +92,19 @@ with gr.Blocks() as demo:
|
|
| 96 |
submit_button_component = gr.Button(value='Submit', variant='primary')
|
| 97 |
|
| 98 |
with gr.Column():
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
)
|
| 114 |
-
elif text in CAPTION_TASK_NAMES or text == OCR_TASK_NAME:
|
| 115 |
-
text_output_component = gr.Textbox(label='Caption Output')
|
| 116 |
-
submit_button_component.click(
|
| 117 |
-
fn=process,
|
| 118 |
-
inputs=[
|
| 119 |
-
checkpoint_dropdown_component,
|
| 120 |
-
task_dropdown_component,
|
| 121 |
-
image_input_component
|
| 122 |
-
],
|
| 123 |
-
outputs=text_output_component
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
@gr.render(inputs=task_dropdown_component)
|
| 127 |
-
def show_examples(text):
|
| 128 |
-
global image_output_component
|
| 129 |
-
global text_output_component
|
| 130 |
-
if text == OBJECT_DETECTION_TASK_NAME:
|
| 131 |
-
gr.Examples(
|
| 132 |
-
fn=process,
|
| 133 |
-
examples=OBJECT_DETECTION_EXAMPLES,
|
| 134 |
-
inputs=[
|
| 135 |
-
checkpoint_dropdown_component,
|
| 136 |
-
task_dropdown_component,
|
| 137 |
-
image_input_component
|
| 138 |
-
],
|
| 139 |
-
outputs=image_output_component
|
| 140 |
-
)
|
| 141 |
-
elif text in CAPTION_TASK_NAMES:
|
| 142 |
-
gr.Examples(
|
| 143 |
-
fn=process,
|
| 144 |
-
examples=CAPTION_EXAMPLES,
|
| 145 |
-
inputs=[
|
| 146 |
-
checkpoint_dropdown_component,
|
| 147 |
-
task_dropdown_component,
|
| 148 |
-
image_input_component
|
| 149 |
-
],
|
| 150 |
-
outputs=text_output_component
|
| 151 |
-
)
|
| 152 |
-
elif text == OCR_TASK_NAME:
|
| 153 |
-
gr.Examples(
|
| 154 |
-
fn=process,
|
| 155 |
-
examples=OCR_EXAMPLES,
|
| 156 |
-
inputs=[
|
| 157 |
-
checkpoint_dropdown_component,
|
| 158 |
-
task_dropdown_component,
|
| 159 |
-
image_input_component
|
| 160 |
-
],
|
| 161 |
-
outputs=text_output_component
|
| 162 |
-
)
|
| 163 |
-
elif text == OCR_WITH_REGION_TASK_NAME:
|
| 164 |
-
gr.Examples(
|
| 165 |
-
fn=process,
|
| 166 |
-
examples=OCR_WITH_REGION_EXAMPLES,
|
| 167 |
-
inputs=[
|
| 168 |
-
checkpoint_dropdown_component,
|
| 169 |
-
task_dropdown_component,
|
| 170 |
-
image_input_component
|
| 171 |
-
],
|
| 172 |
-
outputs=image_output_component
|
| 173 |
-
)
|
| 174 |
|
| 175 |
demo.launch(debug=False, show_error=True, max_threads=1)
|
|
|
|
| 52 |
["microsoft/Florence-2-large-ft", OCR_WITH_REGION_TASK_NAME, "https://media.roboflow.com/inference/license_plate_1.jpg"]
|
| 53 |
]
|
| 54 |
|
| 55 |
+
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 56 |
+
# DEVICE = "cuda"
|
| 57 |
MODELS, PROCESSORS = load_models(DEVICE)
|
| 58 |
|
| 59 |
|
|
|
|
| 74 |
return response[task]
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
with gr.Blocks() as demo:
|
| 78 |
gr.Markdown(MARKDOWN)
|
| 79 |
with gr.Row():
|
|
|
|
| 92 |
submit_button_component = gr.Button(value='Submit', variant='primary')
|
| 93 |
|
| 94 |
with gr.Column():
|
| 95 |
+
image_output_component = gr.Image(type='pil', label='Image Output')
|
| 96 |
+
text_output_component = gr.Textbox(label='Caption Output', visible=False)
|
| 97 |
+
|
| 98 |
+
def on_dropdown_input(text):
|
| 99 |
+
if text in CAPTION_TASK_NAMES + [OCR_TASK_NAME]:
|
| 100 |
+
return [gr.Image(visible=False), gr.Textbox(visible=True)]
|
| 101 |
+
else:
|
| 102 |
+
return [gr.Image(visible=True), gr.Textbox(visible=False)]
|
| 103 |
+
|
| 104 |
+
task_dropdown_component.input(
|
| 105 |
+
on_dropdown_input,
|
| 106 |
+
inputs=[task_dropdown_component],
|
| 107 |
+
outputs=[image_output_component, text_output_component])
|
| 108 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
demo.launch(debug=False, show_error=True, max_threads=1)
|