File size: 1,442 Bytes
cca1c1a
b9fd9ba
d98c3e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4aaa5b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#https://huggingface.co/spaces/diogenemudenge/MDspace
import gradio as gr
import pdfplumber
from transformers import pipeline
from gtts import gTTS
import speech_recognition as sr
import os 


def extract_abstract(text):
    # Simple logic to extract text between 'Abstract' and 'Introduction'
    abstract_start = text.find('Abstract')
    abstract_end = text.find('Introduction', abstract_start)
    return text[abstract_start:abstract_end]

def summarize_abstract(abstract):
    summarizer = pipeline('summarization', model='facebook/bart-large-cnn')
    summary = summarizer(abstract, max_length=130, min_length=30, do_sample=False)
    return summary[0]['summary_text']

def convert_to_speech(text):
    tts = gTTS(text)
    audio_file = 'summary.mp3'
    tts.save(audio_file)
    return audio_file

def my_app_function(pdf_file):
    with pdfplumber.open(pdf_file) as pdf:
        first_page = pdf.pages[0]
        text = first_page.extract_text()
        abstract = extract_abstract(text)
        summary = summarize_abstract(abstract)
        audio_file = convert_to_speech(summary)
        return summary, audio_file

iface = gr.Interface(
    fn=my_app_function,
    inputs=gr.File(),  # Updated line
    outputs=["text", "audio"],
    title="PDF Abstract Summarizer",
    description="This app reads PDFs, summarizes the abstract, and converts the summary to speech. Please upload PDFs with abstracts."
)


iface.launch(share=True)