Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
|
| 4 |
+
fuse_client = Client("https://noamrot-fusecap-image-captioning.hf.space/")
|
| 5 |
+
clipi_client = Client("https://fffiloni-clip-interrogator-2.hf.space/")
|
| 6 |
+
|
| 7 |
+
def compare(image):
|
| 8 |
+
|
| 9 |
+
ci_cap = clipi_client.predict(
|
| 10 |
+
image, # str (filepath or URL to image) in 'parameter_3' Image component
|
| 11 |
+
"best", # str in 'Select mode' Radio component
|
| 12 |
+
2, # int | float (numeric value between 2 and 24) in 'best mode max flavors' Slider component
|
| 13 |
+
api_name="/clipi2"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
fuse_cap = fuse_client.predict(
|
| 17 |
+
image, # str representing input in 'raw_image' Image component
|
| 18 |
+
api_name="/predict"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
coca_cap = "comming soon..."
|
| 22 |
+
|
| 23 |
+
return ci_cap, coca_cap, fuse_cap
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
with gr.Column():
|
| 28 |
+
gr.Markdown("""
|
| 29 |
+
# Caption compare
|
| 30 |
+
""")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
image_in = gr.Image(label="Image to caption", type="filepath")
|
| 35 |
+
submit_btn = gr.Button("Compare !")
|
| 36 |
+
with gr.Column():
|
| 37 |
+
clip_int_out = gr.Textbox(label="Clip Interrogator")
|
| 38 |
+
coca_out = gr.Textbox(label="CoCa")
|
| 39 |
+
fuse_out = gr.Textbox(label="Fuse Cap")
|
| 40 |
+
|
| 41 |
+
submit_btn.click(
|
| 42 |
+
fn = compare,
|
| 43 |
+
inputs = [
|
| 44 |
+
image_in
|
| 45 |
+
],
|
| 46 |
+
outputs = [
|
| 47 |
+
clip_int_out,
|
| 48 |
+
coca_out,
|
| 49 |
+
fuse_out
|
| 50 |
+
]
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
demo.queue().launch()
|