Spaces:
Sleeping
Sleeping
Add video url in output
#1
by
volumetrader
- opened
app.py
CHANGED
|
@@ -17,15 +17,21 @@ num_clusters = 10 # Choose the number of clusters
|
|
| 17 |
kmeans = KMeans(n_clusters=num_clusters, random_state=42)
|
| 18 |
kmeans.fit(encoded_images)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def find_nearest_neighbors(encoded_images, input_image, top_n=5):
|
| 21 |
"""
|
| 22 |
Find the closest neighbors to the input image in the encoded image space.
|
| 23 |
-
|
| 24 |
Args:
|
| 25 |
encoded_images (np.ndarray): Array of encoded images (shape: (n_samples, n_features)).
|
| 26 |
input_image (np.ndarray): The encoded input image (shape: (1, n_features)).
|
| 27 |
top_n (int): The number of nearest neighbors to return.
|
| 28 |
-
|
| 29 |
Returns:
|
| 30 |
List of tuples: (index, distance) of the top_n nearest neighbors.
|
| 31 |
"""
|
|
@@ -79,7 +85,7 @@ def inference(image):
|
|
| 79 |
print(im["label"], im["timestamp"])
|
| 80 |
|
| 81 |
result_image = get_image(top4[0])
|
| 82 |
-
result = f"{result_image['label']} {result_image['timestamp']}"
|
| 83 |
|
| 84 |
n=2
|
| 85 |
plt.figure(figsize=(8, 8))
|
|
|
|
| 17 |
kmeans = KMeans(n_clusters=num_clusters, random_state=42)
|
| 18 |
kmeans.fit(encoded_images)
|
| 19 |
|
| 20 |
+
def create_url_from_title(title: str, timestamp: int):
|
| 21 |
+
video_urls = load_dataset("eybro/video_urls")
|
| 22 |
+
df = video_urls['train'].to_pandas()
|
| 23 |
+
filtered = df[df['title'] == title]
|
| 24 |
+
base_url = df["url"][0]
|
| 25 |
+
return base_url + f"?t={timestamp}s"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
def find_nearest_neighbors(encoded_images, input_image, top_n=5):
|
| 29 |
"""
|
| 30 |
Find the closest neighbors to the input image in the encoded image space.
|
|
|
|
| 31 |
Args:
|
| 32 |
encoded_images (np.ndarray): Array of encoded images (shape: (n_samples, n_features)).
|
| 33 |
input_image (np.ndarray): The encoded input image (shape: (1, n_features)).
|
| 34 |
top_n (int): The number of nearest neighbors to return.
|
|
|
|
| 35 |
Returns:
|
| 36 |
List of tuples: (index, distance) of the top_n nearest neighbors.
|
| 37 |
"""
|
|
|
|
| 85 |
print(im["label"], im["timestamp"])
|
| 86 |
|
| 87 |
result_image = get_image(top4[0])
|
| 88 |
+
result = f"{result_image['label']} {result_image['timestamp']} \n{create_url_from_title(result_image['label'], result_image['timestamp'])}"
|
| 89 |
|
| 90 |
n=2
|
| 91 |
plt.figure(figsize=(8, 8))
|