|
|
|
|
|
|
|
import gradio as gr |
|
import numpy as np |
|
import pandas as pd |
|
|
|
|
|
def similarity_image_search(text, top_k): |
|
|
|
images = [ |
|
("image1.jpg", 0.95), |
|
("image2.jpg", 0.85), |
|
("image3.jpg", 0.75), |
|
("image4.jpg", 0.65), |
|
("image5.jpg", 0.55), |
|
("image6.jpg", 0.45), |
|
("image7.jpg", 0.35), |
|
("image8.jpg", 0.25), |
|
("image9.jpg", 0.15), |
|
("image10.jpg", 0.05), |
|
] |
|
|
|
|
|
images.sort(key=lambda x: x[1], reverse=True) |
|
|
|
|
|
return [img[0] for img in images[:top_k]] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
text_input = gr.Textbox(label="Search Query") |
|
|
|
|
|
top_k_slider = gr.Slider(1, 10, value=5, label="Number of Top Images") |
|
|
|
|
|
image_gallery = gr.Gallery(label="Top Images", columns=3) |
|
|
|
|
|
text_input.submit(similarity_image_search, inputs=[text_input, top_k_slider], outputs=image_gallery) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch(show_error=True) |