MariaKaiser commited on
Commit
a55f6c3
·
verified ·
1 Parent(s): cf9540e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -7,33 +7,33 @@ from pydantic import BaseModel
7
  from typing import List, Optional
8
  from pathlib import Path
9
 
10
-
11
- # MODEL_DIR = "my_model"
12
  OUTPUT_DIR = "outputs"
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
 
15
  device = "cuda" if torch.cuda.is_available() else "cpu"
16
 
17
  from huggingface_hub import hf_hub_download
 
18
  # ------------------------
19
  # Download model files from Hugging Face if not present
20
  # ------------------------
21
  MODEL_DIR = "my_model"
 
22
  config_path = hf_hub_download(
23
- repo_id="MariaKaiser/EGTTS_finetuned",
24
- filename="config.json",
25
  cache_dir=MODEL_DIR
26
  )
27
 
28
  vocab_path = hf_hub_download(
29
- repo_id="MariaKaiser/EGTTS_finetuned",
30
- filename="vocab.json",
31
  cache_dir=MODEL_DIR
32
  )
33
 
34
  model_path = hf_hub_download(
35
- repo_id="MariaKaiser/EGTTS_finetuned",
36
- filename="model.pth",
37
  cache_dir=MODEL_DIR
38
  )
39
 
@@ -330,17 +330,17 @@ async def process_story(story: StoryCreationDTO):
330
  return response
331
 
332
 
333
-
334
- # async def tts_endpoint(
335
- # text: str = Form(...),
336
- # audio_file: UploadFile = File(...)
337
- # ):
338
- # file_path = os.path.join(OUTPUT_DIR, audio_file.filename)
339
- # with open(file_path, "wb") as f:
340
- # f.write(await audio_file.read())
341
-
342
- # output_wav = tts_arabic(text, file_path)
343
- # return FileResponse(output_wav, media_type="audio/wav", filename="output.wav")
344
 
345
  import uvicorn
346
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
7
  from typing import List, Optional
8
  from pathlib import Path
9
 
 
 
10
  OUTPUT_DIR = "outputs"
11
  os.makedirs(OUTPUT_DIR, exist_ok=True)
12
 
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
 
15
  from huggingface_hub import hf_hub_download
16
+
17
  # ------------------------
18
  # Download model files from Hugging Face if not present
19
  # ------------------------
20
  MODEL_DIR = "my_model"
21
+
22
  config_path = hf_hub_download(
23
+ repo_id="MariaKaiser/egtts_finetuned_with_vocab",
24
+ filename="my_model/config.json",
25
  cache_dir=MODEL_DIR
26
  )
27
 
28
  vocab_path = hf_hub_download(
29
+ repo_id="MariaKaiser/egtts_finetuned_with_vocab",
30
+ filename="my_model/vocab.json",
31
  cache_dir=MODEL_DIR
32
  )
33
 
34
  model_path = hf_hub_download(
35
+ repo_id="MariaKaiser/egtts_finetuned_with_vocab",
36
+ filename="my_model/model.pth",
37
  cache_dir=MODEL_DIR
38
  )
39
 
 
330
  return response
331
 
332
 
333
+ @app.post("/tts_test/")
334
+ async def tts_endpoint(
335
+ text: str = Form(...),
336
+ audio_file: UploadFile = File(...)
337
+ ):
338
+ file_path = os.path.join(OUTPUT_DIR, audio_file.filename)
339
+ with open(file_path, "wb") as f:
340
+ f.write(await audio_file.read())
341
+
342
+ output_wav = tts_arabic(text, file_path)
343
+ return FileResponse(output_wav, media_type="audio/wav", filename="output.wav")
344
 
345
  import uvicorn
346
  uvicorn.run(app, host="0.0.0.0", port=7860)