Spaces:
Runtime error
Runtime error
update
Browse files
README.md
CHANGED
|
@@ -1,46 +1,13 @@
|
|
| 1 |
---
|
| 2 |
title: Uniformer_image_demo
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
license: mit
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
`title`: _string_
|
| 15 |
-
Display title for the Space
|
| 16 |
-
|
| 17 |
-
`emoji`: _string_
|
| 18 |
-
Space emoji (emoji-only character allowed)
|
| 19 |
-
|
| 20 |
-
`colorFrom`: _string_
|
| 21 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 22 |
-
|
| 23 |
-
`colorTo`: _string_
|
| 24 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 25 |
-
|
| 26 |
-
`sdk`: _string_
|
| 27 |
-
Can be either `gradio`, `streamlit`, or `static`
|
| 28 |
-
|
| 29 |
-
`sdk_version` : _string_
|
| 30 |
-
Only applicable for `streamlit` SDK.
|
| 31 |
-
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
| 32 |
-
|
| 33 |
-
`app_file`: _string_
|
| 34 |
-
Path to your main application file (which contains either `gradio` or `streamlit` Python code, or `static` html code).
|
| 35 |
-
Path is relative to the root of the repository.
|
| 36 |
-
|
| 37 |
-
`models`: _List[string]_
|
| 38 |
-
HF model IDs (like "gpt2" or "deepset/roberta-base-squad2") used in the Space.
|
| 39 |
-
Will be parsed automatically from your code if not specified here.
|
| 40 |
-
|
| 41 |
-
`datasets`: _List[string]_
|
| 42 |
-
HF dataset IDs (like "common_voice" or "oscar-corpus/OSCAR-2109") used in the Space.
|
| 43 |
-
Will be parsed automatically from your code if not specified here.
|
| 44 |
-
|
| 45 |
-
`pinned`: _boolean_
|
| 46 |
-
Whether the Space stays on top of your list.
|
|
|
|
| 1 |
---
|
| 2 |
title: Uniformer_image_demo
|
| 3 |
+
emoji: 📷
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.0.3
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -49,17 +49,39 @@ def inference(img):
|
|
| 49 |
prediction = F.softmax(prediction, dim=1).flatten()
|
| 50 |
|
| 51 |
return {imagenet_id_to_classname[str(i)]: float(prediction[i]) for i in range(1000)}
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2201.09450' target='_blank'>UniFormer: Unifying Convolution and Self-attention for Visual Recognition</a> | <a href='https://github.com/Sense-X/UniFormer' target='_blank'>Github Repo</a></p>"
|
| 60 |
|
| 61 |
-
|
| 62 |
-
inference, inputs, outputs=label,
|
| 63 |
-
title=title, description=description, article=article,
|
| 64 |
-
examples=[['library.jpeg'], ['cat.png'], ['dog.png'], ['panda.png']]
|
| 65 |
-
).launch(enable_queue=True, cache_examples=True)
|
|
|
|
| 49 |
prediction = F.softmax(prediction, dim=1).flatten()
|
| 50 |
|
| 51 |
return {imagenet_id_to_classname[str(i)]: float(prediction[i]) for i in range(1000)}
|
|
|
|
| 52 |
|
| 53 |
+
def set_example_image(example: list) -> dict:
|
| 54 |
+
return gr.Image.update(value=example[0])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
demo = gr.Blocks()
|
| 58 |
+
with demo:
|
| 59 |
+
gr.Markdown(
|
| 60 |
+
"""
|
| 61 |
+
# UniFormer-S
|
| 62 |
+
Gradio demo for <a href='https://github.com/Sense-X/UniFormer' target='_blank'>UniFormer</a>: To use it, simply upload your image, or click one of the examples to load them. Read more at the links below.
|
| 63 |
+
"""
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
with gr.Box():
|
| 67 |
+
with gr.Row():
|
| 68 |
+
with gr.Column():
|
| 69 |
+
with gr.Row():
|
| 70 |
+
input_image = gr.Image(label='Input Image', type='pil')
|
| 71 |
+
with gr.Row():
|
| 72 |
+
submit_button = gr.Button('Submit')
|
| 73 |
+
with gr.Column():
|
| 74 |
+
label = gr.Label(num_top_classes=5)
|
| 75 |
+
with gr.Row():
|
| 76 |
+
example_images = gr.Dataset(components=[input_image], samples=[['library.jpeg'], ['cat.png'], ['dog.png'], ['panda.png']])
|
| 77 |
+
|
| 78 |
+
gr.Markdown(
|
| 79 |
+
"""
|
| 80 |
+
<p style='text-align: center'><a href='https://arxiv.org/abs/2201.09450' target='_blank'>UniFormer: Unifying Convolution and Self-attention for Visual Recognition</a> | <a href='https://github.com/Sense-X/UniFormer' target='_blank'>Github Repo</a></p>
|
| 81 |
+
"""
|
| 82 |
+
)
|
| 83 |
|
| 84 |
+
submit_button.click(fn=inference, inputs=input_image, outputs=label)
|
| 85 |
+
example_images.click(fn=set_example_image, inputs=example_images, outputs=example_images.components)
|
|
|
|
| 86 |
|
| 87 |
+
demo.launch(enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|