Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -139,12 +139,33 @@ def converti(path):
|
|
139 |
summary = summarizer(abstr, max_length=56)
|
140 |
summary_text = summary[0]['summary_text']
|
141 |
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
import gradio as gr
|
145 |
|
146 |
-
|
147 |
-
# return "Hello " + name + "!!"
|
148 |
-
# return
|
149 |
-
iface = gr.Interface(fn=converti, inputs=gr.Textbox(label="Input PDF name from your drive"), outputs="text")
|
150 |
iface.launch()
|
|
|
139 |
summary = summarizer(abstr, max_length=56)
|
140 |
summary_text = summary[0]['summary_text']
|
141 |
|
142 |
+
import torch
|
143 |
+
import soundfile as sf
|
144 |
+
from IPython.display import Audio
|
145 |
+
from datasets import load_dataset
|
146 |
+
|
147 |
+
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
|
148 |
+
|
149 |
+
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
150 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
151 |
+
|
152 |
+
inputs = processor(text=summary_text, return_tensors="pt")
|
153 |
+
|
154 |
+
from datasets import load_dataset
|
155 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
156 |
+
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
157 |
+
|
158 |
+
spectrogram = model.generate_speech(inputs["input_ids"], speaker_embeddings)
|
159 |
+
|
160 |
+
from transformers import SpeechT5HifiGan
|
161 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
162 |
+
with torch.no_grad():
|
163 |
+
speech = vocoder(spectrogram)
|
164 |
+
|
165 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
166 |
+
return Audio(speech, rate=16000)
|
167 |
|
168 |
import gradio as gr
|
169 |
|
170 |
+
iface = gr.Interface(fn=converti, inputs=gr.Textbox(label="Input PDF name from your drive"), outputs="audio")
|
|
|
|
|
|
|
171 |
iface.launch()
|