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