Spaces:
Running
Running
import gradio as gr | |
import os | |
import random | |
from src.model import simlarity_model as model | |
from src.similarity.similarity import Similarity | |
similarity = Similarity() | |
models = similarity.get_models() | |
def check(img_main, img_1, img_2, model_idx): | |
images = [ | |
(random.choice( | |
[ | |
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80", | |
"https://images.unsplash.com/photo-1554151228-14d9def656e4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=386&q=80", | |
"https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW4lMjBmYWNlfGVufDB8fDB8fA%3D%3D&w=1000&q=80", | |
"https://images.unsplash.com/photo-1546456073-92b9f0a8d413?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80", | |
"https://images.unsplash.com/photo-1601412436009-d964bd02edbc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80", | |
] | |
), f"label {i}" if i != 0 else "label" * 50) | |
for i in range(3) | |
] | |
similarity.check_similarity([img_main, img_1, img_2], models[model_idx]) | |
return [] | |
# def greet(name): | |
# return "Hello " + name + "!!" | |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
# iface.launch() | |
with gr.Blocks() as demo: | |
gr.Markdown('Checking Image Similarity') | |
img_main = gr.Text(label='Main Image', placeholder='https://myimage.jpg') | |
gr.Markdown('Images to check') | |
img_1 = gr.Text(label='1st Image', placeholder='https://myimage_1.jpg') | |
img_2 = gr.Text(label='2nd Image', placeholder='https://myimage_2.jpg') | |
gr.Markdown('Choose the model') | |
model = gr.Dropdown([m.name for m in models], label='Model', type='index') | |
gallery = gr.Gallery( | |
label="Generated images", show_label=True, elem_id="gallery" | |
).style(grid=[2], height="auto") | |
submit_btn = gr.Button('Check Similarity') | |
submit_btn.click(fn=check,inputs=[img_main, img_1, img_2, model], outputs=gallery) | |
demo.launch() |