SummarizeMLPDF is an intuitive and efficient tool designed to extract valuable
insights from machine learning research papers. Simply upload a PDF containing
the article "Hidden Technical Debt in Machine Learning Systems" or any other
machine learning paper, and let SummarizeMLPDF do the rest. Our state-of-the-art
summarization model will analyze the abstract and provide you with a concise,
one-sentence summary, enabling you to grasp the key concepts without delving into
the entire document.
pip install --upgrade pip
pip install --upgrade transformers sentencepiece datasets[audio]
pip install PyPDF2
import PyPDF2
import torch
from transformers import pipeline
from datasets import load_dataset
import soundfile as sf
def extract_pdf(pdf_path):
with open(pdf_path, 'rb') as file:
pdf_reader = PyPDF2.PdfReader(file)
page=pdf_reader.pages[0]
page_text = page.extract_text()
abstract_start = page_text.find("Abstract")
introduction_start = page_text.find("Introduction
if abstract_start != -1 and introduction_start != -1
content = page_text[abstract_start+8:introduction_start-2]
return content
model_name = 'pszemraj/led-large-book-summary'
def summarize_text(text):
summarizer = pipeline(
"summarization",
model_name,
device=0 if torch.cuda.is_available() else -1,
)
summary_output = summarizer(text, max_length=18, min_length=5, length_penalty=2.0, num_beams=4, early_stopping=True)
print(summary_output)
return summary_output
pdf_path = '/content/drive/MyDrive/Article_11.pdf'
text = extract_pdf(pdf_path)
print(text)
summary = summarize_text(text)
text_to_synthesize = summary[0]['summary_text']
synthesiser = pipeline("text-to-speech", "microsoft/speecht5_tts")
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
speaker_embedding = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
speech = synthesiser(text_to_synthesize, forward_params={"speaker_embeddings": speaker_embedding})
sf.write("speech.wav", speech["audio"], samplerate=speech["sampling_rate"])
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
import torch
import soundfile as sf
from datasets import load_dataset
from IPython.display import Audio
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
inputs = processor(text=text_to_synthesize, return_tensors="pt")
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
sf.write("speech.wav", speech.numpy(), samplerate=16000)
Audio("speech.wav")