lord-reso commited on
Commit
f6d0d12
·
verified ·
1 Parent(s): a5201f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
app.py CHANGED
@@ -7,6 +7,13 @@ from typing import Dict
7
  import httpx
8
 
9
  app = FastAPI()
 
 
 
 
 
 
 
10
  app.add_middleware(
11
  CORSMiddleware,
12
  allow_origins=["*"],
@@ -15,36 +22,38 @@ app.add_middleware(
15
  allow_headers=["*"],
16
  )
17
 
18
- @app.get("/")
19
- def read_root():
20
- data = {"Voice": "Cloning", "Status": "Success"}
21
- return JSONResponse(content=data)
22
-
23
- hugging_face_api_url = "https://lord-reso-host.hf.space/synthesize"
24
 
25
  @app.post("/synthesize", response_model=Dict[str, str])
26
- def synthesize(request_data: Dict[str, str]):
 
 
27
  try:
28
  with httpx.Client() as client:
29
  print('try successful')
30
- response = client.post(hugging_face_api_url, json=request_data, timeout=300.0)
31
-
32
  response.raise_for_status() # Raises an HTTPError for bad responses
33
-
34
  # Process the response from Hugging Face API
35
  hugging_face_response = response.json()
36
-
37
  font_type = request_data['font_select']
38
  input_text = request_data['input_text']
39
  print('fetch successful')
40
 
 
 
 
 
 
 
 
 
41
  # Generate mel-spectrogram using Tacotron2
42
  mel_output_data, mel_output_postnet_data, alignments_data = synthesize_voice(input_text, "Shruti_finetuned")
43
- print('Mel generation successful')
44
-
45
  # Convert mel-spectrogram to base64 for display in HTML
46
  mel_output_base64 = plot_data([mel_output_data, mel_output_postnet_data, alignments_data])
47
- print("image conv successful")
48
 
49
  # Save the generated audio file
50
  audio_file_path = 'audio_output/mel1_generated_e2e.wav'
@@ -90,4 +99,4 @@ def synthesize(request_data: Dict[str, str]):
90
  print("Caught exception")
91
  error_message = f"Error during processing: {str(e)}"
92
  print(error_message)
93
- return JSONResponse(content={"error": error_message}, status_code=500)
 
7
  import httpx
8
 
9
  app = FastAPI()
10
+
11
+ @app.get("/")
12
+ def read_root():
13
+ data = {"Voice": "Cloning", "Status": "Success"}
14
+ return JSONResponse(content=data)
15
+
16
+
17
  app.add_middleware(
18
  CORSMiddleware,
19
  allow_origins=["*"],
 
22
  allow_headers=["*"],
23
  )
24
 
25
+ hugging_face_api_url = "https://huggingface.co/spaces/lord-reso/host/synthesize"
 
 
 
 
 
26
 
27
  @app.post("/synthesize", response_model=Dict[str, str])
28
+ async def synthesize(request_data: Dict[str, str]):
29
+ print("call successful")
30
+
31
  try:
32
  with httpx.Client() as client:
33
  print('try successful')
34
+ response = client.post(hugging_face_api_url, json=request_data, timeout=30.0)
 
35
  response.raise_for_status() # Raises an HTTPError for bad responses
 
36
  # Process the response from Hugging Face API
37
  hugging_face_response = response.json()
38
+
39
  font_type = request_data['font_select']
40
  input_text = request_data['input_text']
41
  print('fetch successful')
42
 
43
+ # Font selection logic (customize based on your requirements)
44
+ if font_type == 'Preeti':
45
+ # Implement Preeti font logic
46
+ pass
47
+ elif font_type == 'Unicode':
48
+ # Implement Unicode font logic
49
+ pass
50
+
51
  # Generate mel-spectrogram using Tacotron2
52
  mel_output_data, mel_output_postnet_data, alignments_data = synthesize_voice(input_text, "Shruti_finetuned")
53
+ print("mel generation successful")
54
+
55
  # Convert mel-spectrogram to base64 for display in HTML
56
  mel_output_base64 = plot_data([mel_output_data, mel_output_postnet_data, alignments_data])
 
57
 
58
  # Save the generated audio file
59
  audio_file_path = 'audio_output/mel1_generated_e2e.wav'
 
99
  print("Caught exception")
100
  error_message = f"Error during processing: {str(e)}"
101
  print(error_message)
102
+ return JSONResponse(content={"error": error_message}, status_code=500)