Text2Story / app.py
mkoot007's picture
Update app.py
45c4e80
raw
history blame
No virus
1.19 kB
import streamlit as st
import io
from PIL import Image
import easyocr
from transformers import pipeline
# Create a text2text-generation pipeline with the "google/flan-t5-base" model
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
# Initialize the EasyOCR reader for text extraction from images
ocr_reader = easyocr.Reader(['en'])
st.title("Text Explanation Model")
uploaded_file = st.file_uploader("Upload an image:")
if uploaded_file is not None:
# Read the uploaded image
image = Image.open(uploaded_file)
# Extract text from the image using OCR
ocr_results = ocr_reader.readtext(image)
extracted_text = " ".join([res[1] for res in ocr_results])
st.markdown("**Extracted text:**")
st.markdown(extracted_text)
if extracted_text:
# Use the pipeline to generate a concise explanation
explanation = pipe(extracted_text, max_length=30, do_sample=True)[0]["generated_text"]
st.markdown("**Explanation (5-6 lines):**")
st.markdown(explanation)
else:
st.warning("No text extracted from the image.")
else:
st.markdown("Please upload an image to extract text and generate an explanation.")