jschwab21 commited on
Commit
73d2101
·
verified ·
1 Parent(s): 1dd6469

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -22
app.py CHANGED
@@ -50,27 +50,30 @@ class CustomTheme(Base):
50
  custom_theme = CustomTheme()
51
 
52
  def save_uploaded_file(uploaded_file):
53
- print(f"Received object type: {type(uploaded_file)}")
54
  if uploaded_file is None:
55
  return None # Handle cases where no file was uploaded
56
-
57
- if isinstance(uploaded_file, gr.NamedString):
58
- print(f"File path from NamedString: {uploaded_file}")
59
- return uploaded_file # Directly return the path if it's a NamedString
60
 
61
- upload_dir = "uploaded_videos"
62
- os.makedirs(upload_dir, exist_ok=True)
63
- file_path = os.path.join(upload_dir, uploaded_file.name)
64
 
65
- # Save the temporary file to a new location
66
- with open(file_path, "wb") as f:
67
- f.write(uploaded_file.read()) # Assuming file is a file-like object
68
- f.flush()
69
- os.fsync(f.fileno()) # Ensure all file data is flushed to disk
 
 
 
 
 
 
 
70
 
 
71
  print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes")
72
  return file_path
73
 
 
74
  def display_results(video_url, video_file, description):
75
  final_clip_path = None
76
 
@@ -137,17 +140,18 @@ h3 {
137
  }
138
  """
139
 
140
- with gr.Blocks(theme=custom_theme, css=css) as demo:
141
  with gr.Column():
142
- gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
143
- gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
144
- gr.Markdown("**Welcome to Sickstadium AI. Our goal is to empower content creators with the ability to tell their stories without the friction of traditional video editing software. Skip the timeline, and don't worry about your video editing skills. Upload your video, describe the clip you want, and let our AI video editor do the work for you. Get more info about the Sickstadium project at [Strongholdlabs.io](https://strongholdlabs.io/)**", elem_classes="centered-markdown")
145
- video_url = gr.Textbox(label="Video URL:")
146
- video_file = gr.File(label="Upload Video File:")
147
- description = gr.Textbox(label="Describe your clip:")
148
  submit_button = gr.Button("Process Video")
149
  video_output = gr.Video(label="Processed Video")
150
  download_output = gr.File(label="Download Processed Video")
151
- submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output])
 
 
 
 
152
 
153
- demo.launch()
 
50
  custom_theme = CustomTheme()
51
 
52
  def save_uploaded_file(uploaded_file):
 
53
  if uploaded_file is None:
54
  return None # Handle cases where no file was uploaded
 
 
 
 
55
 
56
+ print(f"Received object type: {type(uploaded_file)}") # Debug: Check the object type
57
+ print(f"Uploaded file content: {uploaded_file}") # Debug: Inspect the content
 
58
 
59
+ # Handling file content based on its type
60
+ if isinstance(uploaded_file, tuple):
61
+ # If it's a tuple, it usually contains (filename, filedata)
62
+ filename, filedata = uploaded_file
63
+ file_path = os.path.join("uploaded_videos", filename)
64
+ with open(file_path, "wb") as f:
65
+ f.write(filedata)
66
+ elif isinstance(uploaded_file, str):
67
+ # If it's a string, assuming it's a file path
68
+ file_path = uploaded_file
69
+ else:
70
+ raise ValueError("Unexpected file input type")
71
 
72
+ os.makedirs(os.path.dirname(file_path), exist_ok=True)
73
  print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes")
74
  return file_path
75
 
76
+
77
  def display_results(video_url, video_file, description):
78
  final_clip_path = None
79
 
 
140
  }
141
  """
142
 
143
+ with gr.Blocks() as demo:
144
  with gr.Column():
145
+ video_url = gr.Textbox(label="Video URL")
146
+ video_file = gr.File(label="Upload Video File", type="file")
147
+ description = gr.Textbox(label="Describe your clip")
 
 
 
148
  submit_button = gr.Button("Process Video")
149
  video_output = gr.Video(label="Processed Video")
150
  download_output = gr.File(label="Download Processed Video")
151
+ submit_button.click(
152
+ fn=display_results,
153
+ inputs=[video_url, video_file, description],
154
+ outputs=[video_output, download_output]
155
+ )
156
 
157
+ demo.launch()