JaMugen commited on
Commit
4e35766
·
1 Parent(s): 9b90754

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -66
app.py CHANGED
@@ -1,38 +1,13 @@
1
- import subprocess as sp
2
-
3
- sp.check_call(['pip', 'install', 'pydrive'])
4
- sp.check_call(['pip', 'install', 'transformers'])
5
- sp.check_call(['pip', 'install', 'requests'])
6
  import os
7
  import json
8
- import subprocess as sp
9
- import requests
10
  from pydrive.auth import GoogleAuth
11
  from pydrive.drive import GoogleDrive
12
  from oauth2client.service_account import ServiceAccountCredentials
13
- import gradio as gr
14
- from gradio import Video
15
-
16
- # Fetching config from Hugging Face Spaces
17
- url = "https://huggingface.co/spaces/CS482Project/Milestone_5-Search_UI_and_pitch_video_voiceover/raw/main/config.json"
18
-
19
- response = requests.get(url)
20
- if response.status_code == 200:
21
- config = response.json()
22
- drive_config = config.get('drive_config')
23
- drive_folder_id = config.get('drive_folder_id')
24
- if drive_config and drive_folder_id:
25
- print(drive_config)
26
- print(drive_folder_id)
27
- else:
28
- print("Drive config or folder ID not found in the JSON.")
29
- else:
30
- print("Failed to fetch data. Status code:", response.status_code)
31
 
 
32
  def download_videos_from_drive(drive, folder_id, save_directory, video_names):
33
- print("Fetching video list from Google Drive...")
34
  file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()
35
- print("Total files in Drive folder:", len(file_list)) # Print total files in the Drive folder
36
  os.makedirs(save_directory, exist_ok=True)
37
  found_videos = []
38
 
@@ -44,48 +19,22 @@ def download_videos_from_drive(drive, folder_id, save_directory, video_names):
44
 
45
  return found_videos
46
 
47
- def view_videos(folder_id, video_names):
48
- video_directory = "Videos"
49
- os.makedirs(video_directory, exist_ok=True)
50
-
51
- print("Downloading videos from Google Drive...")
52
- found_videos = download_videos_from_drive(drive, folder_id, video_directory, video_names)
53
- print("Videos downloaded:", found_videos)
54
- return found_videos
55
-
56
- def display_text(text):
57
- relevant_videos = ['Memphis_Police_Protests,_Super_Bowl_LVII_Matchup_Set_|_NPR_News_Now.mp4', "Maui's_Death_Toll_Rises_To_111_|_NPR_News_Now.mp4", 'Manhunt_Continues_For_Suspect_In_Maine_Shootings_|_NPR_News_Now.mp4', 'Jordan_Calls_For_3rd_Vote_Friday_On_His_Bid_For_House_Speaker_|_NPR_News_Now.mp4', 'Israel_Gives_1M_Civilians_In_Northern_Gaza_24_Hours_To_Evacuate_|_NPR_News_Now.mp4'] # Replace with video names
58
- videos_from_drive = view_videos(drive_folder_id, relevant_videos)
59
- return videos_from_drive
60
-
61
- # Authentication with Google Drive
62
  gauth = GoogleAuth()
63
- gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(drive_config,
64
- ['https://www.googleapis.com/auth/drive'])
65
  drive = GoogleDrive(gauth)
66
 
67
- # Gradio Interface
68
- def display_videos(text):
69
- videos = display_text(text)
70
- video_tags = []
71
-
72
- for video in videos[:5]: # Get the first five videos
73
- abs_video_path = os.path.abspath(video)
74
-
75
- if os.path.exists(abs_video_path):
76
- video_tags.append(Video(abs_video_path))
77
- else:
78
- print(f"Video file '{video}' not found.")
79
-
80
- return video_tags
81
-
82
- iface = gr.Interface(
83
- fn=display_videos,
84
- inputs="text",
85
- outputs="video",
86
- description="Enter text to fetch and display videos from Google Drive"
87
- )
88
 
89
- iface.launch()
 
90
 
 
 
 
 
 
 
91
 
 
 
 
 
 
 
1
  import os
2
  import json
3
+ import streamlit as st
 
4
  from pydrive.auth import GoogleAuth
5
  from pydrive.drive import GoogleDrive
6
  from oauth2client.service_account import ServiceAccountCredentials
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Function to download videos from Drive
9
  def download_videos_from_drive(drive, folder_id, save_directory, video_names):
 
10
  file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()
 
11
  os.makedirs(save_directory, exist_ok=True)
12
  found_videos = []
13
 
 
19
 
20
  return found_videos
21
 
22
+ # Authenticate with Google Drive
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  gauth = GoogleAuth()
24
+ # Add authentication steps here using 'drive_config'
 
25
  drive = GoogleDrive(gauth)
26
 
27
+ # Streamlit app
28
+ st.title("Video Viewer")
29
+ st.markdown("Enter text to fetch and display videos from Google Drive")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ text_input = st.text_input("Enter text:")
32
+ relevant_videos = ['video1.mp4', 'video2.mp4', 'video3.mp4', 'video4.mp4', 'video5.mp4'] # Replace with actual video names
33
 
34
+ if st.button("Fetch Videos"):
35
+ video_directory = "Videos"
36
+ videos = download_videos_from_drive(drive, drive_folder_id, video_directory, relevant_videos)
37
+
38
+ for video in videos[:5]: # Display the first five videos
39
+ st.video(video)
40