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.")