Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
import os
|
| 4 |
+
import uuid
|
| 5 |
+
from utils import generate_sample_video, combine_video_audio
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
async def root():
|
| 12 |
+
return {"message": "FastAPI + MoviePy on Hugging Face is working."}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.post("/generate")
|
| 16 |
+
async def generate():
|
| 17 |
+
output_path = generate_sample_video()
|
| 18 |
+
return FileResponse(output_path, media_type="video/mp4", filename=os.path.basename(output_path))
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@app.post("/combine")
|
| 22 |
+
async def combine(video_file: UploadFile = File(...), audio_file: UploadFile = File(...)):
|
| 23 |
+
output_path = await combine_video_audio(video_file, audio_file)
|
| 24 |
+
return FileResponse(output_path, media_type="video/mp4", filename=os.path.basename(output_path))
|