Update app.py
Browse files1234567891011121314151617182 unmodified lines212223242526271 unmodified line2930313233343519 unmodified lines555657585960616263646566676869import osimport jsonimport subprocess as spsp.check_call(['pip', 'install', 'pydrive'])sp.check_call(['pip', 'install', 'requests'])sp.check_call(['pip', 'install', 'transformers'])from pydrive.auth import GoogleAuthfrom pydrive.drive import GoogleDrivefrom oauth2client.service_account import ServiceAccountCredentialsimport gradio as grimport jsonimport requestsimport jsonimport requestsurl = "https://huggingface.co/spaces/CS482Project/Milestone_5-Search_UI_and_pitch_video_voiceover/raw/main/config.json"response = requests.get(url)2 unmodified linesdrive_config = config.get('drive_config')drive_folder_id = config.get('drive_folder_id')if drive_config and drive_folder_id:# Use the retrieved data as neededprint(drive_config)print(drive_folder_id)else:1 unmodified lineelse:print("Failed to fetch data. Status code:", response.status_code)def download_videos_from_drive(drive, folder_id, save_directory, video_names):file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()os.makedirs(save_directory, exist_ok=True)19 unmodified linesvideos_from_drive = view_videos(drive_folder_id, relevant_videos)return videos_from_drivegauth = GoogleAuth()gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(drive_config,['https://www.googleapis.com/auth/drive'])drive = GoogleDrive(gauth)text_interface = gr.Interface(fn=display_text,inputs="text",outputs=gr.outputs.Video(label="Selected Videos", type="files"))text_interface.launch()123456789101112132 unmodified lines1617181920211 unmodified line23242526272819 unmodified lines484950515253545556575859606162636465666768697071727374import osimport jsonimport subprocess as spimport requestsfrom pydrive.auth import GoogleAuthfrom pydrive.drive import GoogleDrivefrom oauth2client.service_account import ServiceAccountCredentialsimport gradio as gr# Fetching config from Hugging Face Spacesurl = "https://huggingface.co/spaces/CS482Project/Milestone_5-Search_UI_and_pitch_video_voiceover/raw/main/config.json"response = requests.get(url)2 unmodified linesdrive_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:1 unmodified lineelse:print("Failed to fetch data. Status code:", response.status_code)def download_videos_from_drive(drive, folder_id, save_directory, video_names):file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()os.makedirs(save_directory, exist_ok=True)19 unmodified linesvideos_from_drive = view_videos(drive_folder_id, relevant_videos)return videos_from_drive# Authentication with Google Drivegauth = GoogleAuth()gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(drive_config,['https://www.googleapis.com/auth/drive'])drive = GoogleDrive(gauth)# Gradio Interfacedef display_videos(text):videos = display_text(text)video_tags = ""for video in videos:video_tags += f"<video width='320' height='240' controls><source src='{video}' type='video/mp4'></video><br>"return video_tagsiface = gr.Interface(fn=display_videos,inputs="text",outputs="html",title="Video Viewer",description="Enter text to fetch and display videos from Google Drive")iface.launch()
app.py+18-13