azamat commited on
Commit
8e9d0f7
·
1 Parent(s): dd15546

Add video download

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -1,12 +1,28 @@
 
 
1
  import gradio as gr
2
  from weaviate_explorer import WeaviateExplorer
3
 
4
  weaviate_explorer = WeaviateExplorer()
5
  video_player = gr.Video(label="Search Results")
6
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def search(query):
 
8
  shorts = weaviate_explorer.explore(query)
9
- video_player.value = shorts[0]["link"]
 
10
  return video_player, "\n\n".join([f"{r['title']}\n{r['link']}" for r in shorts])
11
 
12
  iface = gr.Interface(fn=search,
 
1
+ import os
2
+ import gdown
3
  import gradio as gr
4
  from weaviate_explorer import WeaviateExplorer
5
 
6
  weaviate_explorer = WeaviateExplorer()
7
  video_player = gr.Video(label="Search Results")
8
 
9
+ downloads_dir = "downloads" # Directory to store downloaded videos
10
+
11
+ # Create the downloads directory if it doesn't exist
12
+ os.makedirs(downloads_dir, exist_ok=True)
13
+
14
+ def remove_downloaded_videos():
15
+ """Remove all downloaded videos from the 'downloads' directory."""
16
+ for file_name in os.listdir(downloads_dir):
17
+ file_path = os.path.join(downloads_dir, file_name)
18
+ if os.path.isfile(file_path):
19
+ os.remove(file_path)
20
+
21
  def search(query):
22
+ remove_downloaded_videos() # Remove previously downloaded videos
23
  shorts = weaviate_explorer.explore(query)
24
+ video_path = gdown.download(shorts[0]["link"], output=downloads_dir, quiet=False)
25
+ video_player.value = video_path
26
  return video_player, "\n\n".join([f"{r['title']}\n{r['link']}" for r in shorts])
27
 
28
  iface = gr.Interface(fn=search,