Spaces:
Runtime error
Runtime error
| 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() | |