JaMugen commited on
Commit
089b70d
·
1 Parent(s): d30a031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -1,18 +1,13 @@
1
  import os
2
  import json
3
  import subprocess as sp
4
- sp.check_call(['pip', 'install', 'pydrive'])
5
- sp.check_call(['pip', 'install', 'requests'])
6
- sp.check_call(['pip', 'install', 'transformers'])
7
  from pydrive.auth import GoogleAuth
8
  from pydrive.drive import GoogleDrive
9
  from oauth2client.service_account import ServiceAccountCredentials
10
  import gradio as gr
11
- import json
12
- import requests
13
- import json
14
- import requests
15
 
 
16
  url = "https://huggingface.co/spaces/CS482Project/Milestone_5-Search_UI_and_pitch_video_voiceover/raw/main/config.json"
17
 
18
  response = requests.get(url)
@@ -21,7 +16,6 @@ if response.status_code == 200:
21
  drive_config = config.get('drive_config')
22
  drive_folder_id = config.get('drive_folder_id')
23
  if drive_config and drive_folder_id:
24
- # Use the retrieved data as needed
25
  print(drive_config)
26
  print(drive_folder_id)
27
  else:
@@ -29,7 +23,6 @@ if response.status_code == 200:
29
  else:
30
  print("Failed to fetch data. Status code:", response.status_code)
31
 
32
-
33
  def download_videos_from_drive(drive, folder_id, save_directory, video_names):
34
  file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()
35
  os.makedirs(save_directory, exist_ok=True)
@@ -55,15 +48,27 @@ def display_text(text):
55
  videos_from_drive = view_videos(drive_folder_id, relevant_videos)
56
  return videos_from_drive
57
 
 
58
  gauth = GoogleAuth()
59
  gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(drive_config,
60
  ['https://www.googleapis.com/auth/drive'])
61
  drive = GoogleDrive(gauth)
62
 
63
- text_interface = gr.Interface(
64
- fn=display_text,
 
 
 
 
 
 
 
 
65
  inputs="text",
66
- outputs=gr.outputs.Video(label="Selected Videos", type="files")
 
 
67
  )
68
 
69
- text_interface.launch()
 
 
1
  import os
2
  import json
3
  import subprocess as sp
4
+ import requests
 
 
5
  from pydrive.auth import GoogleAuth
6
  from pydrive.drive import GoogleDrive
7
  from oauth2client.service_account import ServiceAccountCredentials
8
  import gradio as gr
 
 
 
 
9
 
10
+ # Fetching config from Hugging Face Spaces
11
  url = "https://huggingface.co/spaces/CS482Project/Milestone_5-Search_UI_and_pitch_video_voiceover/raw/main/config.json"
12
 
13
  response = requests.get(url)
 
16
  drive_config = config.get('drive_config')
17
  drive_folder_id = config.get('drive_folder_id')
18
  if drive_config and drive_folder_id:
 
19
  print(drive_config)
20
  print(drive_folder_id)
21
  else:
 
23
  else:
24
  print("Failed to fetch data. Status code:", response.status_code)
25
 
 
26
  def download_videos_from_drive(drive, folder_id, save_directory, video_names):
27
  file_list = drive.ListFile({'q': f"'{folder_id}' in parents and trashed=false"}).GetList()
28
  os.makedirs(save_directory, exist_ok=True)
 
48
  videos_from_drive = view_videos(drive_folder_id, relevant_videos)
49
  return videos_from_drive
50
 
51
+ # Authentication with Google Drive
52
  gauth = GoogleAuth()
53
  gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(drive_config,
54
  ['https://www.googleapis.com/auth/drive'])
55
  drive = GoogleDrive(gauth)
56
 
57
+ # Gradio Interface
58
+ def display_videos(text):
59
+ videos = display_text(text)
60
+ video_tags = ""
61
+ for video in videos:
62
+ video_tags += f"<video width='320' height='240' controls><source src='{video}' type='video/mp4'></video><br>"
63
+ return video_tags
64
+
65
+ iface = gr.Interface(
66
+ fn=display_videos,
67
  inputs="text",
68
+ outputs="html",
69
+ title="Video Viewer",
70
+ description="Enter text to fetch and display videos from Google Drive"
71
  )
72
 
73
+ iface.launch()
74
+