Saqib commited on
Commit
4a7efc9
1 Parent(s): da87cda

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +25 -0
modules/app.py CHANGED
@@ -133,6 +133,31 @@ async def concatenate_videos(request: Request):
133
  print(traceback.format_exc())
134
  raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  @app.get("/get_youtube_audio")
137
  async def get_youtube_audio(request: Request):
138
  try:
 
133
  print(traceback.format_exc())
134
  raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
135
 
136
+ @app.post("/make_video")
137
+ async def make_video(request: Request):
138
+ try:
139
+ # Generate a unique filename for the output
140
+ output_filename = f"{uuid.uuid4()}.mp4"
141
+ output_path = os.path.join(OUTPUT_DIR, output_filename)
142
+
143
+ # Call the modal API with the request data and download the output file
144
+ data = await request.json()
145
+ async with aiohttp.ClientSession() as session:
146
+ async with session.post(f"{MODAL_BASE_URL}/make_video", json=data) as response:
147
+ if response.status != 200:
148
+ raise HTTPException(status_code=500, detail="Failed to process request")
149
+ output_data = await response.read()
150
+ async with aiofiles.open(output_path, "wb") as f:
151
+ await f.write(output_data)
152
+
153
+ # Return the URL path to the output file
154
+ return f"https://sxqib-api.hf.space/output/{output_filename}"
155
+
156
+ except Exception as e:
157
+ print(f"An error occurred: {str(e)}")
158
+ print(traceback.format_exc())
159
+ raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
160
+
161
  @app.get("/get_youtube_audio")
162
  async def get_youtube_audio(request: Request):
163
  try: