Spaces:
Sleeping
Sleeping
ivelin
commited on
Commit
•
c04ab4e
1
Parent(s):
a8e6b52
fix: gradio update related issues
Browse filesSigned-off-by: ivelin <ivelin.eth@gmail.com>
app.py
CHANGED
@@ -15,7 +15,8 @@ def load_model(pretrained_revision: str = 'main'):
|
|
15 |
pretrained_repo_name = 'ivelin/donut-refexp-click'
|
16 |
# revision can be git commit hash, branch or tag
|
17 |
# use 'main' for latest revision
|
18 |
-
print(
|
|
|
19 |
processor = DonutProcessor.from_pretrained(
|
20 |
pretrained_repo_name, revision=pretrained_revision, use_auth_token="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")
|
21 |
processor.image_processor.do_align_long_axis = False
|
@@ -28,10 +29,10 @@ def load_model(pretrained_revision: str = 'main'):
|
|
28 |
print(f'processor image size: {processor.image_processor.size}')
|
29 |
model = VisionEncoderDecoderModel.from_pretrained(
|
30 |
pretrained_repo_name, use_auth_token="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", revision=pretrained_revision)
|
31 |
-
|
32 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
33 |
model.to(device)
|
34 |
-
|
35 |
|
36 |
def prepare_image_for_encoder(image=None, output_image_size=None):
|
37 |
"""
|
@@ -89,13 +90,13 @@ def translate_point_coords_from_out_to_in(point=None, input_image_size=None, out
|
|
89 |
f"translated point={point}, resized_image_size: {resized_width, resized_height}")
|
90 |
|
91 |
|
92 |
-
def process_refexp(image
|
93 |
|
94 |
print(f"(image, prompt): {image}, {prompt}")
|
95 |
|
96 |
if not model_revision:
|
97 |
model_revision = 'main'
|
98 |
-
|
99 |
print(f"model checkpoint revision: {model_revision}")
|
100 |
|
101 |
load_model(model_revision)
|
@@ -222,7 +223,7 @@ examples = [["example_1.jpg", "select the setting icon from top right corner", "
|
|
222 |
|
223 |
demo = gr.Interface(fn=process_refexp,
|
224 |
inputs=[gr.Image(type="pil"), "text", "text"],
|
225 |
-
outputs=[gr.Image(type="pil"), "json"],
|
226 |
title=title,
|
227 |
description=description,
|
228 |
article=article,
|
|
|
15 |
pretrained_repo_name = 'ivelin/donut-refexp-click'
|
16 |
# revision can be git commit hash, branch or tag
|
17 |
# use 'main' for latest revision
|
18 |
+
print(
|
19 |
+
f"Loading model checkpoint from repo: {pretrained_repo_name}, revision: {pretrained_revision}")
|
20 |
processor = DonutProcessor.from_pretrained(
|
21 |
pretrained_repo_name, revision=pretrained_revision, use_auth_token="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")
|
22 |
processor.image_processor.do_align_long_axis = False
|
|
|
29 |
print(f'processor image size: {processor.image_processor.size}')
|
30 |
model = VisionEncoderDecoderModel.from_pretrained(
|
31 |
pretrained_repo_name, use_auth_token="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", revision=pretrained_revision)
|
32 |
+
|
33 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
34 |
model.to(device)
|
35 |
+
|
36 |
|
37 |
def prepare_image_for_encoder(image=None, output_image_size=None):
|
38 |
"""
|
|
|
90 |
f"translated point={point}, resized_image_size: {resized_width, resized_height}")
|
91 |
|
92 |
|
93 |
+
def process_refexp(image, prompt: str, model_revision: str = 'main'):
|
94 |
|
95 |
print(f"(image, prompt): {image}, {prompt}")
|
96 |
|
97 |
if not model_revision:
|
98 |
model_revision = 'main'
|
99 |
+
|
100 |
print(f"model checkpoint revision: {model_revision}")
|
101 |
|
102 |
load_model(model_revision)
|
|
|
223 |
|
224 |
demo = gr.Interface(fn=process_refexp,
|
225 |
inputs=[gr.Image(type="pil"), "text", "text"],
|
226 |
+
outputs=[gr.Image(type="pil", shape=(820)), "json"],
|
227 |
title=title,
|
228 |
description=description,
|
229 |
article=article,
|