| import subprocess as sp |
|
|
| sp.check_call(['pip', 'install', 'pydrive']) |
| sp.check_call(['pip', 'install', 'transformers']) |
| sp.check_call(['pip', 'install', 'requests']) |
| import os |
| import json |
| import subprocess as sp |
| import requests |
| from pydrive.auth import GoogleAuth |
| from pydrive.drive import GoogleDrive |
| from oauth2client.service_account import ServiceAccountCredentials |
| import gradio as gr |
|
|
| |
| url = "https://huggingface.co/spaces/CS482Project/Milestone_5-Search_UI_and_pitch_video_voiceover/raw/main/config.json" |
|
|
| response = requests.get(url) |
| if response.status_code == 200: |
| config = response.json() |
| drive_config = config.get('drive_config') |
| drive_folder_id = config.get('drive_folder_id') |
| if drive_config and drive_folder_id: |
| print(drive_config) |
| print(drive_folder_id) |
| else: |
| print("Drive config or folder ID not found in the JSON.") |
| else: |
| print("Failed to fetch data. Status code:", response.status_code) |
|
|
| def download_videos_from_drive(drive, folder_id, save_directory, video_names): |
| print("Fetching video list from Google Drive...") |
| file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList() |
| print("Total files in Drive folder:", len(file_list)) |
| os.makedirs(save_directory, exist_ok=True) |
| found_videos = [] |
|
|
| for file in file_list: |
| if file['mimeType'] == 'video/mp4' and file['title'] in video_names: |
| output_file = os.path.join(save_directory, file['title']) |
| file.GetContentFile(output_file) |
| found_videos.append(output_file) |
|
|
| return found_videos |
|
|
| def view_videos(folder_id, video_names): |
| video_directory = "Videos" |
| os.makedirs(video_directory, exist_ok=True) |
| |
| print("Downloading videos from Google Drive...") |
| found_videos = download_videos_from_drive(drive, folder_id, video_directory, video_names) |
| print("Videos downloaded:", found_videos) |
| return found_videos |
|
|
| def display_text(text): |
| 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'] |
| videos_from_drive = view_videos(drive_folder_id, relevant_videos) |
| return videos_from_drive |
|
|
| |
| gauth = GoogleAuth() |
| gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(drive_config, |
| ['https://www.googleapis.com/auth/drive']) |
| drive = GoogleDrive(gauth) |
|
|
| |
| def display_videos(text): |
| videos = display_text(text) |
| print(videos[0]) |
| return videos |
|
|
| iface = gr.Interface( |
| fn=display_videos, |
| inputs="text", |
| outputs=[gr.Video(),gr.Video(),gr.Video(),gr.Video(),gr.Video()], |
| title="Video Viewer", |
| description="Enter text to fetch and display videos from Google Drive" |
| ) |
|
|
| iface.launch() |
|
|