eoeooe commited on
Commit
3cdb3e3
·
verified ·
1 Parent(s): 4a01d93

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ 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
+ # --- 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.")