Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from panna import CLIPInterrogator
|
| 4 |
+
|
| 5 |
+
model = CLIPInterrogator()
|
| 6 |
+
css = """
|
| 7 |
+
#col-container {
|
| 8 |
+
margin: 0 auto;
|
| 9 |
+
max-width: 580px;
|
| 10 |
+
}
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
@spaces.GPU
|
| 14 |
+
def infer(image, best_max_flavors):
|
| 15 |
+
image = image.convert('RGB')
|
| 16 |
+
return model.image2text([image], best_max_flavors=best_max_flavors)[0]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
with gr.Blocks(css=css) as demo:
|
| 20 |
+
with gr.Column(elem_id="col-container"):
|
| 21 |
+
gr.Markdown("# CLIP Interrogator.")
|
| 22 |
+
input_image = gr.Image(type='pil')
|
| 23 |
+
with gr.Row():
|
| 24 |
+
flavor_input = gr.Slider(minimum=2, maximum=48, step=2, value=32, label='best mode max flavors')
|
| 25 |
+
run_button = gr.Button("Submit")
|
| 26 |
+
output_text = gr.Textbox(label="Description Output")
|
| 27 |
+
run_button.click(fn=infer, inputs=[input_image, flavor_input], outputs=[output_text], concurrency_limit=10)
|
| 28 |
+
demo.launch(server_name="0.0.0.0")
|