Set up FastAPI for loom-dl
Browse files- app.py +22 -0
- loom-dl.py +22 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import subprocess
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
class VideoRequest(BaseModel):
|
| 8 |
+
url: str
|
| 9 |
+
output_path: str = "out/video.mp4"
|
| 10 |
+
|
| 11 |
+
@app.post("/download")
|
| 12 |
+
def download_video(request: VideoRequest):
|
| 13 |
+
result = subprocess.run(['python3', 'loom-dl.py', request.url, '-o', request.output_path], capture_output=True, text=True)
|
| 14 |
+
|
| 15 |
+
if result.returncode == 0:
|
| 16 |
+
return {"message": "Download successful!", "output_path": request.output_path}
|
| 17 |
+
else:
|
| 18 |
+
raise HTTPException(status_code=500, detail=f"Error: {result.stderr}")
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
import uvicorn
|
| 22 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
loom-dl.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
def download_loom_video(url):
|
| 5 |
+
output_path = "out/video.mp4"
|
| 6 |
+
result = subprocess.run(['python3', 'loom-dl.py', url, '-o', output_path], capture_output=True, text=True)
|
| 7 |
+
|
| 8 |
+
if result.returncode == 0:
|
| 9 |
+
return "Download successful!", output_path
|
| 10 |
+
else:
|
| 11 |
+
return f"Error: {result.stderr}", None
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=download_loom_video,
|
| 15 |
+
inputs="text",
|
| 16 |
+
outputs=["text", "file"],
|
| 17 |
+
title="Loom Video Downloader",
|
| 18 |
+
description="Enter the Loom video URL to download it as an MP4 file."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
fastapi
|
| 4 |
+
uvicorn
|
| 5 |
+
|