Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,24 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
comment = (
|
| 26 |
-
datetime.datetime.now().replace(microsecond=0).isoformat().replace("T", " ")
|
| 27 |
-
)
|
| 28 |
-
return f"# {comment}\n\n{output}"
|
| 29 |
-
|
| 30 |
-
def run(check: bool) -> str:
|
| 31 |
-
if check:
|
| 32 |
-
return run_gpu()
|
| 33 |
-
else:
|
| 34 |
-
comment = (
|
| 35 |
-
datetime.datetime.now().replace(microsecond=0).isoformat().replace("T", " ")
|
| 36 |
-
)
|
| 37 |
-
return f"# {comment}\n\nThis is running on CPU\n\nClick on 'Run on GPU' below to move to GPU instantly and run nvidia-smi"
|
| 38 |
-
|
| 39 |
-
output = gr.Textbox(
|
| 40 |
-
label="Command Output", max_lines=32, elem_id="output_box", value=run(False)
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
with gr.Blocks(css=CUSTOM_CSS) as demo:
|
| 44 |
-
gr.Markdown("#### `zero-gpu`: how to run no on serverless GPU for free on Spaces 🔥")
|
| 45 |
-
|
| 46 |
-
output.render()
|
| 47 |
-
|
| 48 |
-
check = gr.Checkbox(label="Run on GPU")
|
| 49 |
-
|
| 50 |
-
check.change(run, inputs=[check], outputs=output, every=1)
|
| 51 |
-
|
| 52 |
-
demo.queue().launch(show_api=False)
|
|
|
|
| 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 |
+
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 |
+
# แปลงภาพเป็น numpy array
|
| 20 |
+
img_array = np.array(image)
|
| 21 |
+
# ใช้ detail=0 ให้คืนแค่ข้อความ
|
| 22 |
+
result = reader.readtext(img_array, detail=0, paragraph=True)
|
| 23 |
+
# แสดงผล
|
| 24 |
+
st.text_area("Detected Text", "\n".join(result), height=300)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|