Book_Simplifier / app.py
RAMYASRI-39's picture
Update app.py
6c351e2 verified
import gradio as gr
from transformers import pipeline
import easyocr
from PIL import Image
# Load the NLP model for text simplification
simplify_model = pipeline("summarization", model="t5-small")
# Initialize EasyOCR reader
reader = easyocr.Reader(["en"])
def process_image(image):
"""
Extract text from an uploaded image using EasyOCR and simplify it.
"""
# Convert image to text using EasyOCR
results = reader.readtext(image, detail=0)
text = " ".join(results)
if not text.strip():
return "No text detected in the image. Please upload a clear image of the text."
# Simplify the extracted text
simplified_text = simplify_model(text, max_length=50, min_length=10, do_sample=False)[0]["summary_text"]
return simplified_text
# Create a Gradio interface
interface = gr.Interface(
fn=process_image,
inputs="image",
outputs="text",
title="Simplify Book Content",
description="Upload a photo of a book page to get a simplified explanation in simple English.",
)
# Launch the app
if __name__ == "__main__":
interface.launch()