File size: 1,259 Bytes
f4c65ed
22a0a2e
2d6ede7
f4c65ed
61a5ca8
fc06348
b9cf8e5
 
 
 
 
2d6ede7
f4c65ed
61a5ca8
b1f3db6
aa62731
 
 
 
 
fc06348
aa62731
b1f3db6
 
2d6ede7
b1f3db6
2d6ede7
 
 
61a5ca8
2d6ede7
f4c65ed
61a5ca8
f4c65ed
2d6ede7
b1f3db6
2d6ede7
1b331e3
 
 
2d6ede7
61a5ca8
f4c65ed
 
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
import fitz
from transformers import pipeline
import gradio as gr


def extract_text_from_pdf(pdf_content):
    with fitz.open("temp.pdf", pdf_content) as doc:
        text = ""
        for page_num in range(doc.page_count):
            page = doc[page_num]
            text += page.get_text()
    return text


def generate_summary(file_content, user_input_text):
    if file_content:
        if isinstance(file_content, bytes):
            input_text = extract_text_from_pdf(file_content)
        else:
            input_text = file_content.read().decode("utf-8")
    else:
        input_text = user_input_text
    text_generator = pipeline("text2text-generation", model="google/flan-t5-base")

    summary = text_generator(input_text, max_length=1024, num_beams=4)

    return {
        "Extracted Information": input_text,
        "Book Summary": summary[0]["generated_text"],
        "Review": "The book conveys a powerful message about...",
    }


iface = gr.Interface(
    fn=generate_summary,
    inputs=[gr.File(label="Upload File"), gr.Textbox(label="Enter Text")],
    outputs=[
        gr.Textbox(label="Extracted Information"),
        gr.Textbox(label="Book Summary"),
        gr.Textbox(label="Rewiew"),
    ],
    live=True,
)
iface.launch()