Saqib commited on
Commit
c636ab9
1 Parent(s): 4550586

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +4 -6
modules/app.py CHANGED
@@ -3,11 +3,9 @@ from fastapi.staticfiles import StaticFiles
3
  from pytubefix import YouTube
4
  from pytubefix.exceptions import PytubeFixError
5
  from concurrent.futures import ThreadPoolExecutor
6
- import ffmpeg
7
  import asyncio
8
  import aiohttp
9
  import aiofiles
10
- import requests
11
  import tempfile
12
  import uuid
13
  import base64
@@ -118,15 +116,15 @@ async def get_audio(request: Request):
118
  unique_filename = f"{uuid.uuid4().hex}.mp3"
119
  out_file = os.path.join(AUDIO_DIR, unique_filename)
120
 
121
- # Call the modal API with the request data and download the output file
122
  data = await request.json()
123
  async with aiohttp.ClientSession() as session:
124
- async with session.post(f"{MODAL_BASE_URL}/get_audio", json=data) as response:
125
  if response.status != 200:
126
  raise HTTPException(status_code=500, detail="Failed to process request")
127
- output_data = await response.read()
128
  async with aiofiles.open(out_file, "wb") as f:
129
- await f.write(output_data)
130
 
131
  # Return the URL path to the output file
132
  return f"https://sxqib-api.hf.space/audio/{unique_filename}"
 
3
  from pytubefix import YouTube
4
  from pytubefix.exceptions import PytubeFixError
5
  from concurrent.futures import ThreadPoolExecutor
 
6
  import asyncio
7
  import aiohttp
8
  import aiofiles
 
9
  import tempfile
10
  import uuid
11
  import base64
 
116
  unique_filename = f"{uuid.uuid4().hex}.mp3"
117
  out_file = os.path.join(AUDIO_DIR, unique_filename)
118
 
119
+ # Call the modal API with the request parameters and download the output file
120
  data = await request.json()
121
  async with aiohttp.ClientSession() as session:
122
+ async with session.get(f"{MODAL_BASE_URL}/get_audio", params=data) as response:
123
  if response.status != 200:
124
  raise HTTPException(status_code=500, detail="Failed to process request")
125
+ audio_data = await response.read()
126
  async with aiofiles.open(out_file, "wb") as f:
127
+ await f.write(audio_data)
128
 
129
  # Return the URL path to the output file
130
  return f"https://sxqib-api.hf.space/audio/{unique_filename}"