Miszmisz commited on
Commit
754a99d
·
1 Parent(s): 11348d5

test: singular file download option

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. main.py +26 -12
  3. requirements.txt +1 -1
.gitignore CHANGED
@@ -1 +1,2 @@
1
  .venv/
 
 
1
  .venv/
2
+ ffmpgvenv/
main.py CHANGED
@@ -11,6 +11,7 @@ app = FastAPI()
11
  aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID']
12
  aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY']
13
  s3_bucket_name = os.environ['S3_BUCKET_NAME']
 
14
  aws_region = 'eu-central-1'
15
  temp_dir = '/tmp/'
16
  # Initialize an S3 client
@@ -19,25 +20,38 @@ s3_client = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_a
19
  class CutRequest(BaseModel):
20
  segments: list[tuple[float, float]]
21
 
22
- def download_files(output_key: str):
23
- # Temporary directory to store uploaded audio files
24
-
25
- s3_directory = output_key
26
-
27
- input_files = ['genBase.mp3', 'quote.mp3']
28
  try:
29
- for input_file in input_files:
30
- s3_object_key = f'{s3_directory}/{input_file}'
31
- local_file = temp_dir + input_file
32
- s3_client.download_file(s3_bucket_name, s3_object_key, local_file)
33
  except Exception as e:
34
- raise HTTPException(status_code=500, detail=f"Failed to download files from S3: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  @app.post("/cut-audio/{output_key}")
37
  def cut_audio(request: CutRequest, output_key: str):
38
  download_files(output_key)
39
  for i, (start, end) in enumerate(request.segments):
40
- output_file = f"/tmp/genBase_segment_{i}.mp3"
 
41
  try:
42
  (
43
  ffmpeg
 
11
  aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID']
12
  aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY']
13
  s3_bucket_name = os.environ['S3_BUCKET_NAME']
14
+ aws_env = os.environ['AWS_ENV']
15
  aws_region = 'eu-central-1'
16
  temp_dir = '/tmp/'
17
  # Initialize an S3 client
 
20
  class CutRequest(BaseModel):
21
  segments: list[tuple[float, float]]
22
 
23
+ def download_file(news_name: str,quote_filename: str):
24
+ # Define a function to download a single file
25
+ s3_directory = f'{aws_env}/{news_name}'
26
+ input_file = quote_filename
 
 
27
  try:
28
+ s3_object_key = f'{s3_directory}/{input_file}'
29
+ local_file = temp_dir + input_file
30
+ s3_client.download_file(s3_bucket_name, s3_object_key, local_file)
 
31
  except Exception as e:
32
+ raise HTTPException(status_code=500, detail=f"Failed to download a file from S3: {e}")
33
+
34
+
35
+ # def download_files(output_key: str):
36
+
37
+ # # Temporary directory to store uploaded audio files
38
+ # s3_directory = output_key
39
+
40
+ # input_files = ['genBase.mp3', 'quote.mp3']
41
+ # try:
42
+ # for input_file in input_files:
43
+ # s3_object_key = f'{s3_directory}/{input_file}'
44
+ # local_file = temp_dir + input_file
45
+ # s3_client.download_file(s3_bucket_name, s3_object_key, local_file)
46
+ # except Exception as e:
47
+ # raise HTTPException(status_code=500, detail=f"Failed to download files from S3: {e}")
48
 
49
  @app.post("/cut-audio/{output_key}")
50
  def cut_audio(request: CutRequest, output_key: str):
51
  download_files(output_key)
52
  for i, (start, end) in enumerate(request.segments):
53
+ output_file = f"/tmp/cut_quote_{i}.mp3"
54
+ # output_file = f"/tmp/genBase_segment_{i}.mp3"
55
  try:
56
  (
57
  ffmpeg
requirements.txt CHANGED
@@ -19,5 +19,5 @@ six==1.16.0
19
  sniffio==1.3.0
20
  starlette==0.32.0.post1
21
  typing_extensions==4.9.0
22
- urllib3==2.0.7
23
  uvicorn==0.25.0
 
19
  sniffio==1.3.0
20
  starlette==0.32.0.post1
21
  typing_extensions==4.9.0
22
+ urllib3
23
  uvicorn==0.25.0