Saqib commited on
Commit
02f3fa6
1 Parent(s): 2cd1847

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +24 -0
modules/app.py CHANGED
@@ -84,6 +84,30 @@ async def add_audio_to_image(request: Request):
84
  print(traceback.format_exc())
85
  raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  @app.post("/concatenate_videos")
88
  async def concatenate_videos(request: Request):
89
  try:
 
84
  print(traceback.format_exc())
85
  raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
86
 
87
+ @app.post("/add_audio_to_video")
88
+ async def add_audio_to_video(request: Request):
89
+ try:
90
+ # Generate a unique filename
91
+ output_filename = f"{uuid.uuid4()}.mp4"
92
+ output_path = os.path.join(OUTPUT_DIR, output_filename)
93
+
94
+ # Call the modal API with the request data and download the output file
95
+ data = await request.json()
96
+ async with aiohttp.ClientSession() as session:
97
+ async with session.post(f"{MODAL_BASE_URL}/add_audio_to_video", json=data) as response:
98
+ if response.status != 200:
99
+ raise HTTPException(status_code=500, detail="Failed to process request")
100
+ output_data = await response.read()
101
+ async with aiofiles.open(output_path, "wb") as f:
102
+ await f.write(output_data)
103
+
104
+ # Return the URL path to the output file
105
+ return f"https://sxqib-api.hf.space/output/{output_filename}"
106
+ except Exception as e:
107
+ print(f"An error occurred: {str(e)}")
108
+ print(traceback.format_exc())
109
+ raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
110
+
111
  @app.post("/concatenate_videos")
112
  async def concatenate_videos(request: Request):
113
  try: