File size: 1,281 Bytes
3cdb3e3 |
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 |
import streamlit as st
import easyocr
from PIL import Image
import numpy as np
# โหลด EasyOCR ด้วย GPU (โหลดครั้งเดียวตอนเริ่มแอป)
reader = easyocr.Reader(['en', 'th'], gpu=True)
# --- Streamlit UI ---
st.set_page_config(page_title="EasyOCR (GPU) - Fast OCR")
st.title("EasyOCR (GPU) - Fast OCR")
st.write("Upload an image to extract text using GPU acceleration")
# อัปโหลดไฟล์
uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
# เปิดภาพและแสดง
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
if st.button("Run OCR"):
with st.spinner("Processing..."):
# แปลงภาพเป็น numpy array
img_array = np.array(image)
# ใช้ detail=0 และ paragraph=True
result = reader.readtext(img_array, detail=0, paragraph=True)
if result:
st.success("OCR Completed!")
st.text_area("Detected Text", "\n".join(result), height=300)
else:
st.warning("No text detected in the image.")
|