eoeooe commited on
Commit
99f1bdd
·
verified ·
1 Parent(s): 38207ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -52
app.py CHANGED
@@ -1,52 +1,24 @@
1
- import spaces
2
- import datetime
3
- import os
4
- import subprocess
5
- import torch
6
- import gradio as gr
7
-
8
- CUSTOM_CSS = """
9
- #output_box textarea {
10
- font-family: IBM Plex Mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
11
- }
12
- """
13
-
14
- zero = torch.Tensor([0]).cuda()
15
- print(zero.device) # <-- 'cpu' 🤔
16
-
17
- @spaces.GPU
18
- def run_gpu() -> str:
19
- print(zero.device) # <-- 'cuda:0' 🤗
20
- output: str = ""
21
- try:
22
- output = subprocess.check_output(["nvidia-smi"], text=True)
23
- except FileNotFoundError:
24
- output = "nvidia-smi failed"
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)