Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,21 +50,12 @@ class CustomTheme(Base):
|
|
50 |
custom_theme = CustomTheme()
|
51 |
|
52 |
def save_uploaded_file(uploaded_file):
|
53 |
-
|
54 |
-
print("No file uploaded.")
|
55 |
-
return None # Handle cases where no file was uploaded
|
56 |
-
|
57 |
-
print("File received:", type(uploaded_file), len(uploaded_file))
|
58 |
upload_dir = "uploaded_videos"
|
59 |
os.makedirs(upload_dir, exist_ok=True)
|
60 |
-
file_path = os.path.join(upload_dir,
|
61 |
-
|
62 |
with open(file_path, "wb") as f:
|
63 |
-
f.write(uploaded_file) # Write
|
64 |
-
f.flush()
|
65 |
-
os.fsync(f.fileno()) # Ensure all file data is flushed to disk
|
66 |
-
|
67 |
-
print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes") # Debugging
|
68 |
return file_path
|
69 |
|
70 |
def display_results(video_file):
|
@@ -134,16 +125,23 @@ def interface_function(video_file):
|
|
134 |
return f"File saved at {file_path}"
|
135 |
return "No file uploaded."
|
136 |
|
137 |
-
def test_upload(
|
138 |
-
if
|
139 |
-
return f"Received file with {len(video_file)} bytes"
|
140 |
-
else:
|
141 |
return "No file uploaded."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
with gr.Blocks() as demo:
|
144 |
with gr.Column():
|
145 |
video_file = gr.UploadButton("Upload Video File", type="binary", file_types=["video"])
|
146 |
-
output = gr.Textbox()
|
147 |
submit_button = gr.Button("Process Video")
|
148 |
submit_button.click(
|
149 |
fn=test_upload,
|
|
|
50 |
custom_theme = CustomTheme()
|
51 |
|
52 |
def save_uploaded_file(uploaded_file):
|
53 |
+
import os
|
|
|
|
|
|
|
|
|
54 |
upload_dir = "uploaded_videos"
|
55 |
os.makedirs(upload_dir, exist_ok=True)
|
56 |
+
file_path = os.path.join(upload_dir, uploaded_file.name)
|
|
|
57 |
with open(file_path, "wb") as f:
|
58 |
+
f.write(uploaded_file.file.read()) # Write the content to the new file
|
|
|
|
|
|
|
|
|
59 |
return file_path
|
60 |
|
61 |
def display_results(video_file):
|
|
|
125 |
return f"File saved at {file_path}"
|
126 |
return "No file uploaded."
|
127 |
|
128 |
+
def test_upload(uploaded_file):
|
129 |
+
if uploaded_file is None:
|
|
|
|
|
130 |
return "No file uploaded."
|
131 |
+
# Assuming the file is saved in a temporary location and processed
|
132 |
+
file_path = save_uploaded_file(uploaded_file) # Ensure this function saves and returns the path
|
133 |
+
if not file_path:
|
134 |
+
return "Failed to save file."
|
135 |
+
# Process the video using the path
|
136 |
+
result_path = process_video(file_path, description="Describe your clip here", is_url=False)
|
137 |
+
if not result_path:
|
138 |
+
return "Failed to process video or no scenes found."
|
139 |
+
return f"Video processed and saved to: {result_path}"
|
140 |
|
141 |
with gr.Blocks() as demo:
|
142 |
with gr.Column():
|
143 |
video_file = gr.UploadButton("Upload Video File", type="binary", file_types=["video"])
|
144 |
+
output = gr.Textbox(label="Output")
|
145 |
submit_button = gr.Button("Process Video")
|
146 |
submit_button.click(
|
147 |
fn=test_upload,
|