Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,6 +43,15 @@ class VideoRetrieval:
|
|
| 43 |
"A quiet moment of reflection before a life-changing decision"
|
| 44 |
]
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
data = []
|
| 47 |
for i in range(n_clips):
|
| 48 |
data.append({
|
|
@@ -50,7 +59,8 @@ class VideoRetrieval:
|
|
| 50 |
'movie_title': movie_titles[i % len(movie_titles)],
|
| 51 |
'description': descriptions[i % len(descriptions)],
|
| 52 |
'timestamp': f'{(i*5):02d}:00 - {(i*5+3):02d}:00',
|
| 53 |
-
'duration': '3:00'
|
|
|
|
| 54 |
})
|
| 55 |
|
| 56 |
self.clips_df = pd.DataFrame(data)
|
|
@@ -110,6 +120,7 @@ class VideoRetrieval:
|
|
| 110 |
'movie_title': self.clips_df.iloc[idx]['movie_title'],
|
| 111 |
'description': self.clips_df.iloc[idx]['description'],
|
| 112 |
'timestamp': self.clips_df.iloc[idx]['timestamp'],
|
|
|
|
| 113 |
'similarity_score': float(combined_similarities[idx]) # Convert to float for JSON serialization
|
| 114 |
})
|
| 115 |
|
|
@@ -165,12 +176,20 @@ def main():
|
|
| 165 |
st.markdown(f"**Scene Description:**")
|
| 166 |
st.write(result['description'])
|
| 167 |
st.text(f"⏱️ Timestamp: {result['timestamp']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
with cols[1]:
|
| 170 |
st.markdown("**Relevance Score:**")
|
| 171 |
score = min(1.0, max(0.0, result['similarity_score']))
|
| 172 |
st.progress(score)
|
| 173 |
st.text(f"{score:.2%} match")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
st.divider()
|
| 176 |
|
|
|
|
| 43 |
"A quiet moment of reflection before a life-changing decision"
|
| 44 |
]
|
| 45 |
|
| 46 |
+
# Sample YouTube clips (famous movie scenes)
|
| 47 |
+
youtube_clips = [
|
| 48 |
+
"https://www.youtube.com/watch?v=kcsNbQRU5TI", # Matrix - Red Pill Blue Pill
|
| 49 |
+
"https://www.youtube.com/watch?v=YoHD9XEInc0", # Inception - Hallway Fight
|
| 50 |
+
"https://www.youtube.com/watch?v=ZWCAf-xLV2k", # Dark Knight - Interrogation
|
| 51 |
+
"https://www.youtube.com/watch?v=Jomr9SAjcyw", # Pulp Fiction - Restaurant
|
| 52 |
+
"https://www.youtube.com/watch?v=SQ7_5MMbPYs", # Shawshank - Hope Speech
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
data = []
|
| 56 |
for i in range(n_clips):
|
| 57 |
data.append({
|
|
|
|
| 59 |
'movie_title': movie_titles[i % len(movie_titles)],
|
| 60 |
'description': descriptions[i % len(descriptions)],
|
| 61 |
'timestamp': f'{(i*5):02d}:00 - {(i*5+3):02d}:00',
|
| 62 |
+
'duration': '3:00',
|
| 63 |
+
'youtube_url': youtube_clips[i % len(youtube_clips)]
|
| 64 |
})
|
| 65 |
|
| 66 |
self.clips_df = pd.DataFrame(data)
|
|
|
|
| 120 |
'movie_title': self.clips_df.iloc[idx]['movie_title'],
|
| 121 |
'description': self.clips_df.iloc[idx]['description'],
|
| 122 |
'timestamp': self.clips_df.iloc[idx]['timestamp'],
|
| 123 |
+
'youtube_url': self.clips_df.iloc[idx]['youtube_url'],
|
| 124 |
'similarity_score': float(combined_similarities[idx]) # Convert to float for JSON serialization
|
| 125 |
})
|
| 126 |
|
|
|
|
| 176 |
st.markdown(f"**Scene Description:**")
|
| 177 |
st.write(result['description'])
|
| 178 |
st.text(f"⏱️ Timestamp: {result['timestamp']}")
|
| 179 |
+
|
| 180 |
+
# Add video player
|
| 181 |
+
if result['youtube_url']:
|
| 182 |
+
st.video(result['youtube_url'])
|
| 183 |
|
| 184 |
with cols[1]:
|
| 185 |
st.markdown("**Relevance Score:**")
|
| 186 |
score = min(1.0, max(0.0, result['similarity_score']))
|
| 187 |
st.progress(score)
|
| 188 |
st.text(f"{score:.2%} match")
|
| 189 |
+
|
| 190 |
+
# Add direct YouTube link
|
| 191 |
+
st.markdown(f"[🔗 Watch on YouTube]({result['youtube_url']})")
|
| 192 |
+
st.text("Click to open in a new tab")
|
| 193 |
|
| 194 |
st.divider()
|
| 195 |
|