Sambhavnoobcoder commited on
Commit
d1d085b
·
1 Parent(s): 6fa7850

last code forgot input and output . just here to fix that.(lets hope )

Browse files
Files changed (1) hide show
  1. app.py +38 -41
app.py CHANGED
@@ -15,55 +15,52 @@ def read_pdf(file):
15
 
16
  def main():
17
  logging.basicConfig(level=logging.INFO)
18
- with gr.Interface(fn=None, title="PDF TO SPEECH CONVERTER", layout="rows", debug=True) as iface:
19
- repo_files = list_repo_files(repo_id="balacoon/tts")
20
- model_files = [x for x in repo_files if x.endswith("_cpu.addon")]
21
- model_name = gr.inputs.Dropdown(label="Model", choices=model_files)
22
- speaker = gr.inputs.Dropdown(label="Speaker", choices=[])
23
 
24
- def set_model(model_name_str):
25
- """
26
- Gets value from `model_name`, loads the model,
27
- re-initializes the tts object, and gets a list of
28
- speakers that the model supports and sets them to `speaker`.
29
- """
30
- model_path = hf_hub_download(repo_id="balacoon/tts", filename=model_name_str)
31
- global tts
32
- tts = TTS(model_path)
33
- speakers = tts.get_speakers()
34
- value = speakers[-1]
35
- speaker.choices = speakers
36
- speaker.value = value
37
 
38
- model_name.onChange(set_model)
39
 
40
- file_input = gr.inputs.File(label="Select a PDF File", type="file")
41
- text = gr.outputs.Textbox()
42
 
43
- def synthesize_audio(file, model_name_str, speaker_str):
44
- """
45
- Gets the selected PDF `file`, model name from `model_name`,
46
- and speaker name from `speaker`. Synthesizes the audio waveform
47
- from the text extracted from the PDF and returns it.
48
- """
49
- if file is None or file.name == "":
50
- logging.info("No file selected.")
51
- return None
52
 
53
- text_str = read_pdf(file)
54
- if len(text_str) > 1024:
55
- text_str = text_str[:1024]
56
 
57
- global tts
58
- samples = cast(TTS, tts).synthesize(text_str, speaker_str)
59
- return (cast(TTS, tts).get_sampling_rate(), samples)
60
 
61
- audio = gr.outputs.Audio(label="Generated Audio")
62
 
63
- iface.inputs = [file_input, model_name, speaker]
64
- iface.outputs = audio
65
- iface.fn = synthesize_audio
66
- iface.launch()
67
 
68
 
69
  if __name__ == "__main__":
 
15
 
16
  def main():
17
  logging.basicConfig(level=logging.INFO)
18
+ repo_files = list_repo_files(repo_id="balacoon/tts")
19
+ model_files = [x for x in repo_files if x.endswith("_cpu.addon")]
20
+ model_name = gr.inputs.Dropdown(label="Model", choices=model_files)
21
+ speaker = gr.inputs.Dropdown(label="Speaker", choices=[])
 
22
 
23
+ def set_model(model_name_str):
24
+ """
25
+ Gets value from `model_name`, loads the model,
26
+ re-initializes the tts object, and gets a list of
27
+ speakers that the model supports and sets them to `speaker`.
28
+ """
29
+ model_path = hf_hub_download(repo_id="balacoon/tts", filename=model_name_str)
30
+ global tts
31
+ tts = TTS(model_path)
32
+ speakers = tts.get_speakers()
33
+ value = speakers[-1]
34
+ speaker.choices = speakers
35
+ speaker.value = value
36
 
37
+ model_name.onChange(set_model)
38
 
39
+ file_input = gr.inputs.File(label="Select a PDF File", type="file")
40
+ text = gr.outputs.Textbox()
41
 
42
+ def synthesize_audio(file, model_name_str, speaker_str):
43
+ """
44
+ Gets the selected PDF `file`, model name from `model_name`,
45
+ and speaker name from `speaker`. Synthesizes the audio waveform
46
+ from the text extracted from the PDF and returns it.
47
+ """
48
+ if file is None or file.name == "":
49
+ logging.info("No file selected.")
50
+ return None
51
 
52
+ text_str = read_pdf(file)
53
+ if len(text_str) > 1024:
54
+ text_str = text_str[:1024]
55
 
56
+ global tts
57
+ samples = cast(TTS, tts).synthesize(text_str, speaker_str)
58
+ return (cast(TTS, tts).get_sampling_rate(), samples)
59
 
60
+ audio = gr.outputs.Audio(label="Generated Audio")
61
 
62
+ iface = gr.Interface(fn=synthesize_audio, inputs=[file_input, model_name, speaker], outputs=audio, title="PDF TO SPEECH CONVERTER", layout="rows", debug=True)
63
+ iface.launch()
 
 
64
 
65
 
66
  if __name__ == "__main__":