-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
103 lines (86 loc) · 3.74 KB
/
app.py
File metadata and controls
103 lines (86 loc) · 3.74 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from flask import Flask, request, jsonify
from dotenv import load_dotenv
from services.video_processor import start_video_processing
from services.job_manager import job_manager
import os, time, json, logging
from datetime import datetime
# Configure logging to show debug messages
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
load_dotenv()
app = Flask(__name__)
@app.route("/process", methods=["POST"])
def process_video():
"""Start async video processing and return job ID immediately"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"\n{'='*60}")
print(f"[{timestamp}] 🎬 NEW ASYNC VIDEO PROCESSING REQUEST")
print(f"{'='*60}")
data = request.get_json()
video_url = data.get("video_url")
video_id = data.get("video_id")
clip_duration = data.get("clip_duration", "60")
webhook_url = data.get("webhook_url")
platform = data.get("platform", "YouTube")
style = data.get("style", "default")
transcription_method = data.get("transcription_method", "faster-whisper")
aspect_ratio = data.get("aspect_ratio", "9:16")
enable_face_focus = data.get("enable_face_focus", True)
resolution = data.get("resolution", "360p")
print(f"[{timestamp}] 📝 Request Parameters - URL: {video_url}, Duration: {clip_duration}s, Platform: {platform}, Style: {style}, Transcription: {transcription_method}, Aspect Ratio: {aspect_ratio}, Face Focus: {enable_face_focus}, Resolution: {resolution}, Webhook: {webhook_url}")
# Validation
if not video_url:
return jsonify({"error": "video_url is required"}), 400
if transcription_method not in ["groq", "faster-whisper"]:
return jsonify({"error": "transcription_method must be 'groq' or 'faster-whisper'"}), 400
# Start async processing
job_data = {
"video_url": video_url,
"video_id": video_id, # Pass video_id through to the processing pipeline
"clip_duration": clip_duration,
"webhook_url": webhook_url,
"platform": platform,
"style": style,
"transcription_method": transcription_method,
"aspect_ratio": aspect_ratio,
"enable_face_focus": enable_face_focus,
"resolution": resolution
}
job_id = start_video_processing(job_data)
print(f"[{timestamp}] ✅ Job {job_id} started - processing in background", flush=True)
print(f"[{timestamp}] 🔄 Background thread initiated for job {job_id}", flush=True)
print(f"{'='*60}\n", flush=True)
return jsonify({
"status": "accepted",
"job_id": job_id,
"message": "Video processing started. Use /status/{job_id} to check progress.",
"status_url": f"/status/{job_id}"
}), 202
@app.route("/status/<job_id>", methods=["GET"])
def get_job_status(job_id):
"""Get the status of a processing job"""
job = job_manager.get_job(job_id)
if not job:
return jsonify({"error": "Job not found"}), 404
return jsonify({
"job_id": job_id,
"status": job["status"].value,
"progress": job.get("progress", 0),
"message": job.get("message", ""),
"result": job.get("result"),
"error": job.get("error"),
"created_at": job.get("created_at"),
"updated_at": job.get("updated_at")
})
@app.route("/status/health", methods=["GET"])
def health_check():
"""Health check endpoint for Docker"""
return jsonify({
"status": "healthy",
"timestamp": datetime.now().isoformat(),
"service": "clipfactory-python"
})
if __name__ == "__main__":
print("🚀 Starting ClipFactory Python Server...")
print("📡 Endpoint: http://0.0.0.0:8000/process")
print("-" * 50)
app.run(host="0.0.0.0", port=8000, debug=False)