lord-reso commited on
Commit
3f674bb
·
verified ·
1 Parent(s): 3353131

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -46
app.py CHANGED
@@ -3,8 +3,7 @@ from fastapi.responses import JSONResponse
3
  from fastapi.middleware.cors import CORSMiddleware
4
  from logic import synthesize_voice, plot_data, plot_waveforms
5
  import base64
6
- from typing import Dict
7
- import httpx
8
 
9
  app = FastAPI()
10
 
@@ -25,27 +24,17 @@ app.add_middleware(
25
  hugging_face_api_url = "https://huggingface.co/spaces/lord-reso/host/synthesize"
26
 
27
  @app.post("/synthesize")
28
- async def synthesize(request: Request, request: Request)
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
- json = await request.json
39
  print(json)
40
- # font_type = json['font_select']
41
- # input_text = request_data['input_text']
42
- # print(font_type)
43
- # print(input_text)
44
-
45
 
46
-
 
 
47
  # Generate mel-spectrogram using Tacotron2
48
- mel_output_data, mel_output_postnet_data, alignments_data = synthesize_voice(input_text, "Shruti_finetuned")
49
  print("mel generation successful")
50
 
51
  # Convert mel-spectrogram to base64 for display in HTML
@@ -63,35 +52,10 @@ async def synthesize(request: Request, request: Request)
63
 
64
  # Customize the response based on the information you want to send to the frontend
65
  response_data = {
66
- 'mel_spectrogram': mel_output_base64,
67
  'audio_data': audio_base64,
68
  'waveform': wave_base64,
69
  'some_other_data': 'example_value',
70
- 'hugging_face_response': hugging_face_response, # Include Hugging Face API response
71
-
72
  return JSONResponse(content=response_data)
73
- # except httpx.RequestError as e:
74
- # print("Caught httpx.RequestError")
75
- # import traceback
76
- # error_message = f"Request error: {str(e)}"
77
- # traceback.print_exc()
78
- # print(error_message)
79
- # return JSONResponse(content={"error": error_message}, status_code=500)
80
-
81
- # except httpx.ReadTimeout:
82
- # print("Caught httpx.ReadTimeout")
83
- # error_message = "Request to Hugging Face API timed out."
84
- # print(error_message)
85
- # return JSONResponse(content={"error": error_message}, status_code=500)
86
-
87
- # except httpx.HTTPStatusError as e:
88
- # print("Caught httpx.HTTPStatusError")
89
- # error_message = f"HTTP error: {e.response.text}"
90
- # print(error_message)
91
- # return JSONResponse(content={"error": error_message}, status_code=500)
92
-
93
- # except Exception as e:
94
- # print("Caught exception")
95
- # error_message = f"Error during processing: {str(e)}"
96
- # print(error_message)
97
- # return JSONResponse(content={"error": error_message}, status_code=500)
 
3
  from fastapi.middleware.cors import CORSMiddleware
4
  from logic import synthesize_voice, plot_data, plot_waveforms
5
  import base64
6
+
 
7
 
8
  app = FastAPI()
9
 
 
24
  hugging_face_api_url = "https://huggingface.co/spaces/lord-reso/host/synthesize"
25
 
26
  @app.post("/synthesize")
27
+ async def synthesize(request: Request):
28
  print("call successful")
29
 
30
+ json = await request.json()
 
 
 
 
 
 
 
31
  print(json)
 
 
 
 
 
32
 
33
+ font_type = json['font_select']
34
+ input_text = json['input_text']
35
+
36
  # Generate mel-spectrogram using Tacotron2
37
+ mel_output_data, mel_output_postnet_data, alignments_data = synthesize_voice(input_text, "Shruti_finetuned.pt")
38
  print("mel generation successful")
39
 
40
  # Convert mel-spectrogram to base64 for display in HTML
 
52
 
53
  # Customize the response based on the information you want to send to the frontend
54
  response_data = {
55
+ 'mel_spectrogram': mel_output_base64,
56
  'audio_data': audio_base64,
57
  'waveform': wave_base64,
58
  'some_other_data': 'example_value',
59
+ # 'hugging_face_response': hugging_face_response, # Include Hugging Face API response
60
+ }
61
  return JSONResponse(content=response_data)