Spaces:
Sleeping
Sleeping
File size: 1,766 Bytes
05ae0b9 |
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 |
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Optional
import uvicorn
import os
from agent import app as agent_app
app = FastAPI(title="Continuity", description="AI Video Bridging Service")
class BridgeRequest(BaseModel):
url_a: str
url_c: str
notes: Optional[str] = None
@app.post("/create-bridge")
async def create_bridge(request: BridgeRequest):
"""
Orchestrates the creation of a bridge video between two input clips.
"""
try:
# Initialize LangGraph state
initial_state = {
"video_a_url": request.url_a,
"video_c_url": request.url_c,
"user_notes": request.notes,
"scene_analysis": None,
"veo_prompt": None,
"generated_video_url": None
}
print(f"Starting bridge generation for: {request.url_a} -> {request.url_c}")
# Invoke the graph
result = agent_app.invoke(initial_state)
video_url = result.get("generated_video_url")
analysis = result.get("scene_analysis")
# Check for error strings in the URL field as per agent logic
if video_url and "Error" in video_url:
raise HTTPException(status_code=500, detail=video_url)
if not video_url:
raise HTTPException(status_code=500, detail="Failed to generate video (No URL returned)")
return {
"video_url": video_url,
"analysis_summary": analysis
}
except Exception as e:
# Catch unexpected errors
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|