vettorazi commited on
Commit
615046d
1 Parent(s): 9c98f95

testing deleting fast api

Browse files
Files changed (1) hide show
  1. main.py +15 -34
main.py CHANGED
@@ -9,15 +9,12 @@ import torch
9
  import soundfile as sf
10
  from demucs.apply import apply_model
11
  from demucs.pretrained import DEFAULT_MODEL, get_model
12
- from fastapi import FastAPI, UploadFile, File
13
  from huggingface_hub import hf_hub_download, list_repo_files
14
- from starlette.responses import StreamingResponse
15
 
16
  from so_vits_svc_fork.hparams import HParams
17
  from so_vits_svc_fork.inference.core import Svc
18
 
19
- app = FastAPI()
20
-
21
  ###################################################################
22
  # REPLACE THESE VALUES TO CHANGE THE MODEL REPO/CKPT NAME/SETTINGS
23
  ###################################################################
@@ -102,36 +99,20 @@ def predict(
102
  return model.target_sample, out
103
 
104
 
105
- @app.post("/voice_cloning/")
106
- async def voice_cloning(
107
- speaker: str,
108
- file: UploadFile = File(...),
109
- transpose: int = 0,
110
- auto_predict_f0: bool = False,
111
- cluster_infer_ratio: float = default_cluster_infer_ratio,
112
- noise_scale: float = 0.4,
113
- f0_method: str = default_f0_method,
114
- ):
115
- # Process the audio file
116
- audio_bytes = await file.read()
117
- with io.BytesIO(audio_bytes) as audio_io:
118
- sample_rate, audio_data = predict(
119
- speaker,
120
- audio_io,
121
- transpose=transpose,
122
- auto_predict_f0=auto_predict_f0,
123
- cluster_infer_ratio=cluster_infer_ratio,
124
- noise_scale=noise_scale,
125
- f0_method=f0_method
126
- )
127
- # Create a BytesIO object to hold the audio data
128
- audio_byte_stream = io.BytesIO()
129
- # Write the audio data to the BytesIO object
130
- sf.write(audio_byte_stream, audio_data, sample_rate, format="wav")
131
- # Create a StreamingResponse to return the audio
132
- return StreamingResponse(io.BytesIO(audio_byte_stream.getvalue()), media_type="audio/wav")
133
 
 
134
 
135
  if __name__ == "__main__":
136
- import uvicorn
137
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
9
  import soundfile as sf
10
  from demucs.apply import apply_model
11
  from demucs.pretrained import DEFAULT_MODEL, get_model
12
+ import gradio as gr
13
  from huggingface_hub import hf_hub_download, list_repo_files
 
14
 
15
  from so_vits_svc_fork.hparams import HParams
16
  from so_vits_svc_fork.inference.core import Svc
17
 
 
 
18
  ###################################################################
19
  # REPLACE THESE VALUES TO CHANGE THE MODEL REPO/CKPT NAME/SETTINGS
20
  ###################################################################
 
99
  return model.target_sample, out
100
 
101
 
102
+ def voice_cloning(speaker, audio):
103
+ sample_rate, audio_data = predict(speaker, audio)
104
+ return audio_data, sample_rate
105
+
106
+
107
+ # Configure the Gradio interface
108
+ inputs = [
109
+ gr.inputs.Dropdown(choices=speakers, label="Speaker"),
110
+ gr.inputs.Audio(label="Audio")
111
+ ]
112
+
113
+ outputs = gr.outputs.Audio(label="Cloned Audio")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
+ iface = gr.Interface(fn=voice_cloning, inputs=inputs, outputs=outputs)
116
 
117
  if __name__ == "__main__":
118
+ iface.launch()