lord-reso commited on
Commit
1820ac3
·
verified ·
1 Parent(s): 16b2007
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -4,6 +4,7 @@ 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
 
8
  app = FastAPI()
9
 
@@ -26,34 +27,24 @@ app.add_middleware(
26
  allow_headers=["*"],
27
  )
28
 
 
 
 
29
  @app.post("/synthesize", response_model=Dict[str, str])
30
  async def synthesize(request_data: Dict[str, str]):
31
- font_type = request_data['font_select']
32
- input_text = request_data['input_text']
33
-
34
- # Font selection logic (customize based on your requirements)
35
- if font_type == 'Preeti':
36
- # Implement Preeti font logic
37
- pass
38
- elif font_type == 'Unicode':
39
- # Implement Unicode font logic
40
- pass
41
-
42
- # Generate mel-spectrogram using Tacotron2
43
- mel_output_data, mel_output_postnet_data, alignments_data = synthesize_voice(input_text, "Shruti_finetuned")
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
 
48
- # Save the generated audio file
49
- audio_file_path = 'audio_output/mel1_generated_e2e.wav'
 
50
 
51
- # Plot the waveform
52
- wave_base64 = plot_waveforms(audio_file_path)
 
 
53
 
54
- # Encode audio content as Base64
55
- with open(audio_file_path, 'rb') as audio_file:
56
- audio_base64 = base64.b64encode(audio_file.read()).decode('utf-8')
57
 
58
  # Customize the response based on the information you want to send to the frontend
59
  response_data = {
@@ -61,6 +52,7 @@ async def synthesize(request_data: Dict[str, str]):
61
  'audio_data': audio_base64,
62
  'waveform': wave_base64,
63
  'some_other_data': 'example_value',
 
64
  }
65
 
66
- return JSONResponse(content=response_data)
 
4
  from logic import synthesize_voice, plot_data, plot_waveforms
5
  import base64
6
  from typing import Dict
7
+ import httpx # Import the httpx library for making HTTP requests
8
 
9
  app = FastAPI()
10
 
 
27
  allow_headers=["*"],
28
  )
29
 
30
+ # Hugging Face API URL
31
+ hugging_face_api_url = "https://huggingface.co/spaces/lord-reso/host/synthesize"
32
+
33
  @app.post("/synthesize", response_model=Dict[str, str])
34
  async def synthesize(request_data: Dict[str, str]):
35
+ # Your existing code...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ # Make a request to the Hugging Face API via the proxy
38
+ async with httpx.AsyncClient() as client:
39
+ response = await client.post(hugging_face_api_url, json=request_data)
40
 
41
+ # Check if the request to Hugging Face API was successful
42
+ if response.status_code != 200:
43
+ error_message = f"Error from Hugging Face API: {response.text}"
44
+ return JSONResponse(content={"error": error_message}, status_code=500)
45
 
46
+ # Process the response from Hugging Face API
47
+ hugging_face_response = response.json()
 
48
 
49
  # Customize the response based on the information you want to send to the frontend
50
  response_data = {
 
52
  'audio_data': audio_base64,
53
  'waveform': wave_base64,
54
  'some_other_data': 'example_value',
55
+ 'hugging_face_response': hugging_face_response, # Include Hugging Face API response
56
  }
57
 
58
+ return JSONResponse(content=response_data)