Spaces:
Runtime error
Runtime error
Add initial version of the app
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
from datasets import load_dataset
|
4 |
+
from sentence_transformers import SentenceTransformer, util
|
5 |
+
|
6 |
+
model = SentenceTransformer('clip-ViT-B-32')
|
7 |
+
|
8 |
+
def fake_gan():
|
9 |
+
images = [
|
10 |
+
(random.choice(
|
11 |
+
[
|
12 |
+
"https://upload.wikimedia.org/wikipedia/commons/6/69/NASA-HS201427a-HubbleUltraDeepField2014-20140603.jpg",
|
13 |
+
"https://upload.wikimedia.org/wikipedia/commons/7/73/Cycliste_%C3%A0_place_d%27Italie-Paris.jpg",
|
14 |
+
"https://upload.wikimedia.org/wikipedia/commons/3/31/Great_white_shark_south_africa.jpg",
|
15 |
+
]
|
16 |
+
), f"label {i}" if i != 0 else "label" * 50)
|
17 |
+
for i in range(3)
|
18 |
+
]
|
19 |
+
return images
|
20 |
+
|
21 |
+
def search_images_from_text(text):
|
22 |
+
emb = model.encode(text)
|
23 |
+
return fake_gan()
|
24 |
+
|
25 |
+
def search_images_from_image(image):
|
26 |
+
image_emb = model.encode(image)
|
27 |
+
return fake_gan()
|
28 |
+
|
29 |
+
def main():
|
30 |
+
text_to_image_iface = gr.Interface(fn=search_images_from_text, inputs="text", outputs="gallery")
|
31 |
+
image_to_image_iface = gr.Interface(fn=search_images_from_image, inputs="image", outputs="gallery")
|
32 |
+
demo = gr.TabbedInterface([text_to_image_iface, image_to_image_iface], ["Text query", "Image query"])
|
33 |
+
demo.launch()
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
main()
|