import subprocess subprocess.run(["pip", "install", "PyPDF2", "transformers", "bark", "gradio"]) import PyPDF2 from transformers import pipeline from bark import SAMPLE_RATE, generate_audio, preload_models import gradio as gr def summarize_and_convert_to_audio(pdf_file, abstract_page): # Save the uploaded file pdf_path = "/tmp/uploaded_file.pdf" pdf_file.save(pdf_path) # Convert abstract_page to integer abstract_page = int(abstract_page) with open(pdf_path, 'rb') as file: pdf_reader = PyPDF2.PdfReader(file) # Get the abstract page text abstract_page_text = pdf_reader.pages[abstract_page - 1].extract_text() summarizer = pipeline("summarization", model="facebook/bart-large-cnn") summary = summarizer(abstract_page_text, max_length=20, min_length=20) preload_models() text = summary[0]['summary_text'] audio_array = generate_audio(text) return Audio(audio_array, rate=SAMPLE_RATE) iface = gr.Interface( fn=summarize_and_convert_to_audio, inputs=[ gr.File("application/pdf", label="Upload PDF file"), "text" ], outputs="audio", live=True ) iface.launch()