Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -259,15 +259,18 @@ pdf_path=os.path.join(os.path.abspath(""), "hidden-technical-debt-in-machine-lea
|
|
| 259 |
pdf_path2=os.path.join(os.path.abspath(""), "1812_05944.pdf")
|
| 260 |
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
# =======================================
|
| 267 |
#
|
| 268 |
# =======================================
|
| 269 |
def sentence_to_audio(fileobj):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
|
|
|
| 271 |
# text mining from pdf
|
| 272 |
text_per_page = read_pdf(fileobj.name)
|
| 273 |
text_per_page.keys()
|
|
@@ -293,15 +296,30 @@ def sentence_to_audio(fileobj):
|
|
| 293 |
summary_text=summary[0].get("summary_text")
|
| 294 |
|
| 295 |
# Sentence 2 Speech
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
|
| 307 |
# ============================================================================================
|
|
|
|
| 259 |
pdf_path2=os.path.join(os.path.abspath(""), "1812_05944.pdf")
|
| 260 |
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
# =======================================
|
| 263 |
#
|
| 264 |
# =======================================
|
| 265 |
def sentence_to_audio(fileobj):
|
| 266 |
+
from transformers import pipeline, AutoProcessor, AutoModel
|
| 267 |
+
import torch
|
| 268 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 269 |
+
from transformers import pipeline
|
| 270 |
+
import numpy as np
|
| 271 |
+
import scipy
|
| 272 |
|
| 273 |
+
|
| 274 |
# text mining from pdf
|
| 275 |
text_per_page = read_pdf(fileobj.name)
|
| 276 |
text_per_page.keys()
|
|
|
|
| 296 |
summary_text=summary[0].get("summary_text")
|
| 297 |
|
| 298 |
# Sentence 2 Speech
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
#txt1="Hello ->> " + fileobj.name + " <<!"
|
| 302 |
+
#txt1="Hello"
|
| 303 |
+
#txt2="ciccio"
|
| 304 |
+
|
| 305 |
+
# Sentence 2 Speech
|
| 306 |
+
s_to_s = pipeline("text-to-speech", model="suno/bark-small")
|
| 307 |
+
generated_audio=s_to_s(summary_text,forward_params={"do_sample": True})
|
| 308 |
+
scipy.io.wavfile.write("s_2_s.wav", rate=generated_audio["sampling_rate"], data=generated_audio["audio"].T)
|
| 309 |
+
return "s_2_s.wav",summary_text
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
# processor = AutoProcessor.from_pretrained("suno/bark-small")
|
| 315 |
+
# model = AutoModel.from_pretrained("suno/bark-small")
|
| 316 |
+
# inputs = processor(
|
| 317 |
+
# text=summary_text,
|
| 318 |
+
# return_tensors="pt",
|
| 319 |
+
# )
|
| 320 |
+
# speech_values = model.generate(**inputs, do_sample=True)
|
| 321 |
+
# sampling_rate = model.generation_config.sample_rate
|
| 322 |
+
# return sampling_rate, speech_values.cpu().numpy().squeeze(),summary_text
|
| 323 |
|
| 324 |
|
| 325 |
# ============================================================================================
|