Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -22,14 +22,14 @@ split_dataset = dataset['train'].train_test_split(test_size=0.2, seed=42) # 80%
|
|
22 |
dataset['train'] = split_dataset['train']
|
23 |
dataset['test'] = split_dataset['test']
|
24 |
|
25 |
-
|
26 |
def create_url_from_title(title: str, timestamp: int):
|
27 |
video_urls = load_dataset("eybro/video_urls")
|
28 |
df = video_urls['train'].to_pandas()
|
|
|
29 |
filtered = df[df['title'] == title]
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
def find_nearest_neighbors(encoded_images, input_image, top_n=5):
|
35 |
"""
|
@@ -88,8 +88,10 @@ def inference(image):
|
|
88 |
print(im["label"], im["timestamp"])
|
89 |
|
90 |
result_image = get_image(top4[0])
|
91 |
-
|
92 |
-
|
|
|
|
|
93 |
n=2
|
94 |
plt.figure(figsize=(8, 8))
|
95 |
for i, (image1, image2) in enumerate(zip(top4[:2], top4[2:])):
|
@@ -110,9 +112,17 @@ def inference(image):
|
|
110 |
|
111 |
return result
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
dataset['train'] = split_dataset['train']
|
23 |
dataset['test'] = split_dataset['test']
|
24 |
|
|
|
25 |
def create_url_from_title(title: str, timestamp: int):
|
26 |
video_urls = load_dataset("eybro/video_urls")
|
27 |
df = video_urls['train'].to_pandas()
|
28 |
+
print(df.to_string())
|
29 |
filtered = df[df['title'] == title]
|
30 |
+
print(filtered)
|
31 |
+
base_url = filtered.iloc[0, :]["url"]
|
32 |
+
return base_url + f"&t={timestamp}s"
|
33 |
|
34 |
def find_nearest_neighbors(encoded_images, input_image, top_n=5):
|
35 |
"""
|
|
|
88 |
print(im["label"], im["timestamp"])
|
89 |
|
90 |
result_image = get_image(top4[0])
|
91 |
+
url = create_url_from_title(result_image['label'], result_image['timestamp'])
|
92 |
+
result = f"{result_image['label']} {result_image['timestamp']} \n{url}"
|
93 |
+
#result = f"[This is a link to the video]({url})"
|
94 |
+
|
95 |
n=2
|
96 |
plt.figure(figsize=(8, 8))
|
97 |
for i, (image1, image2) in enumerate(zip(top4[:2], top4[2:])):
|
|
|
112 |
|
113 |
return result
|
114 |
|
115 |
+
with gr.Blocks() as demo:
|
116 |
+
gr.Markdown(
|
117 |
+
"""
|
118 |
+
# Image to Video App
|
119 |
+
Upload an image from a Gordon Ramsay show to find the corresponding youtube video
|
120 |
+
""")
|
121 |
+
with gr.Column(scale=1):
|
122 |
+
inp = gr.Image(label='Upload image')
|
123 |
+
with gr.Column(scale=1):
|
124 |
+
out = gr.Markdown()
|
125 |
+
inp.change(inference, inp, out)
|
126 |
+
|
127 |
+
if __name__ == "__main__":
|
128 |
+
demo.launch()
|