File size: 901 Bytes
c240e04
 
56744d1
c240e04
56744d1
c240e04
 
 
 
56744d1
c240e04
56744d1
c240e04
 
 
56744d1
c240e04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline
from PIL import Image
import os

# Set up the OCR pipeline
@st.cache_resource
def load_model():
    return pipeline("image-to-text", model="microsoft/trocr-base-stage1")

ocr_model = load_model()

# Streamlit UI
st.title("Image Data Extractor using Hugging Face")
st.write("Upload an image, and this app will extract text from it using a Hugging Face model.")

# Upload an image
uploaded_image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])

if uploaded_image:
    # Display the image
    image = Image.open(uploaded_image)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Run OCR on the image
    with st.spinner("Extracting text..."):
        text = ocr_model(image.convert("RGB"))
    
    # Display the extracted text
    st.subheader("Extracted Text:")
    st.write(text[0]['generated_text'])