jschwab21 commited on
Commit
2977112
·
verified ·
1 Parent(s): 51efef6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -50,20 +50,26 @@ class CustomTheme(Base):
50
  custom_theme = CustomTheme()
51
 
52
  def save_uploaded_file(uploaded_file):
53
- """Save the uploaded file to disk."""
54
  if uploaded_file is None:
55
- return None # No file was uploaded
56
 
57
- # Gradio uploads come with a .name attribute and file content is accessible via .read()
58
- upload_dir = "uploaded_videos"
59
- os.makedirs(upload_dir, exist_ok=True)
60
- file_path = os.path.join(upload_dir, uploaded_file.name)
 
 
61
 
62
- # Save the temporary file to a new location
63
- with open(file_path, "wb") as f:
64
- f.write(uploaded_file.read()) # Read bytes from the uploaded file
65
-
66
- return file_path
 
 
 
 
67
 
68
  def display_results(video_url, video_file, description):
69
  """Process video from URL or file upload and return the results."""
 
50
  custom_theme = CustomTheme()
51
 
52
  def save_uploaded_file(uploaded_file):
53
+ print(f"Received object type: {type(uploaded_file)}") # Debug: Check the object type
54
  if uploaded_file is None:
55
+ return None # Handle cases where no file was uploaded
56
 
57
+ # Check if the received object has the expected 'file' and 'name' attributes
58
+ if hasattr(uploaded_file, 'name') and hasattr(uploaded_file, 'file'):
59
+ print(f"File name: {uploaded_file.name}") # Debug: Print file name
60
+ upload_dir = "uploaded_videos"
61
+ os.makedirs(upload_dir, exist_ok=True)
62
+ file_path = os.path.join(upload_dir, uploaded_file.name)
63
 
64
+ with open(file_path, "wb") as f:
65
+ # Attempt to read from the file object if possible
66
+ file_content = uploaded_file.file.read()
67
+ f.write(file_content) # Save file content to disk
68
+ return file_path
69
+ else:
70
+ # If expected attributes are not found, print available attributes
71
+ print(f"Available attributes: {dir(uploaded_file)}") # Debug: List attributes
72
+ return None
73
 
74
  def display_results(video_url, video_file, description):
75
  """Process video from URL or file upload and return the results."""