-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
45 lines (34 loc) · 1.28 KB
/
server.py
File metadata and controls
45 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask, request
import os
import time
from src.pipelines.core.tools import separation # Ensure this module exists
app = Flask(__name__)
UPLOAD_FOLDER = './data/raw/uploaded_videos'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
def clean_dir(directory: str) -> None:
"""Deletes all files in the specified directory."""
for file in os.listdir(directory):
filepath = os.path.join(directory, file)
print(f"Deleting {filepath}")
os.remove(filepath)
@app.route('/upload', methods=['POST'])
def upload_file():
"""Handles file uploads."""
clean_dir(UPLOAD_FOLDER)
if 'file' not in request.files:
return 'No file part', 400
file = request.files['file']
if file.filename == '':
return 'No selected file', 400
# Generate a unique filename
# filename = f"uploaded_{int(time.time())}_{file.filename}"
filename = f"uploaded_{file.filename}"
file_path = os.path.join(UPLOAD_FOLDER, filename)
# Save the uploaded file
file.save(file_path)
print(f'File uploaded successfully: {filename}')
# Process video
separation.separate_video_audio(video_path=file_path)
return f'File uploaded successfully: {filename}', 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)