Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
@@ -20,3 +20,32 @@ iface = gr.Interface(
|
|
20 |
description="Generate videos using AI from text input."
|
21 |
)
|
22 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
description="Generate videos using AI from text input."
|
21 |
)
|
22 |
iface.launch()
|
23 |
+
from fastapi import FastAPI, UploadFile
|
24 |
+
import ffmpeg
|
25 |
+
from transformers import pipeline
|
26 |
+
|
27 |
+
app = FastAPI()
|
28 |
+
|
29 |
+
# Load Hugging Face model (example: text-to-video)
|
30 |
+
model = pipeline("text-to-video-generation", model="damo-vilab/modelscope-text-to-video-synthesis")
|
31 |
+
|
32 |
+
@app.post("/generate_video/")
|
33 |
+
async def generate_video(prompt: str):
|
34 |
+
# Generate video from text
|
35 |
+
result = model(prompt)
|
36 |
+
output_file = "generated_video.mp4"
|
37 |
+
with open(output_file, "wb") as f:
|
38 |
+
f.write(result["video"])
|
39 |
+
|
40 |
+
return {"message": "Video generated successfully!", "file_path": output_file}
|
41 |
+
|
42 |
+
@app.post("/upload_video/")
|
43 |
+
async def upload_video(file: UploadFile):
|
44 |
+
input_file = f"uploaded_{file.filename}"
|
45 |
+
with open(input_file, "wb") as f:
|
46 |
+
f.write(file.file.read())
|
47 |
+
|
48 |
+
# Example: Trim video using FFmpeg
|
49 |
+
trimmed_file = "trimmed_video.mp4"
|
50 |
+
ffmpeg.input(input_file).output(trimmed_file, ss=0, t=10).run()
|
51 |
+
return {"message": "Video uploaded and trimmed!", "file_path": trimmed_file}
|