Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,22 +3,31 @@ import easyocr
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# โหลด EasyOCR ด้วย GPU
|
| 7 |
-
reader = easyocr.Reader(['en','th'], gpu=True)
|
| 8 |
|
|
|
|
|
|
|
| 9 |
st.title("EasyOCR (GPU) - Fast OCR")
|
| 10 |
st.write("Upload an image to extract text using GPU acceleration")
|
| 11 |
|
|
|
|
| 12 |
uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
|
| 13 |
|
| 14 |
if uploaded_file is not None:
|
|
|
|
| 15 |
image = Image.open(uploaded_file)
|
| 16 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 17 |
|
| 18 |
if st.button("Run OCR"):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# โหลด EasyOCR ด้วย GPU (โหลดครั้งเดียวตอนเริ่มแอป)
|
| 7 |
+
reader = easyocr.Reader(['en', 'th'], gpu=True)
|
| 8 |
|
| 9 |
+
# --- Streamlit UI ---
|
| 10 |
+
st.set_page_config(page_title="EasyOCR (GPU) - Fast OCR")
|
| 11 |
st.title("EasyOCR (GPU) - Fast OCR")
|
| 12 |
st.write("Upload an image to extract text using GPU acceleration")
|
| 13 |
|
| 14 |
+
# อัปโหลดไฟล์
|
| 15 |
uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
|
| 16 |
|
| 17 |
if uploaded_file is not None:
|
| 18 |
+
# เปิดภาพและแสดง
|
| 19 |
image = Image.open(uploaded_file)
|
| 20 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 21 |
|
| 22 |
if st.button("Run OCR"):
|
| 23 |
+
with st.spinner("Processing..."):
|
| 24 |
+
# แปลงภาพเป็น numpy array
|
| 25 |
+
img_array = np.array(image)
|
| 26 |
+
# ใช้ detail=0 และ paragraph=True
|
| 27 |
+
result = reader.readtext(img_array, detail=0, paragraph=True)
|
| 28 |
+
|
| 29 |
+
if result:
|
| 30 |
+
st.success("OCR Completed!")
|
| 31 |
+
st.text_area("Detected Text", "\n".join(result), height=300)
|
| 32 |
+
else:
|
| 33 |
+
st.warning("No text detected in the image.")
|