Spaces:
Sleeping
Sleeping
File size: 1,103 Bytes
5d80cb7 6c351e2 5d80cb7 6c351e2 5d80cb7 6c351e2 5d80cb7 6c351e2 5d80cb7 6c351e2 5d80cb7 6c351e2 5d80cb7 |
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 |
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()
|