Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
from transformers import AutoModel, AutoTokenizer
|
4 |
from PIL import Image
|
@@ -6,12 +5,11 @@ import os
|
|
6 |
import base64
|
7 |
import uuid
|
8 |
import time
|
9 |
-
import shutil
|
10 |
from pathlib import Path
|
11 |
|
12 |
# Load tokenizer and model on CPU
|
13 |
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
14 |
-
model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True)
|
15 |
model = model.eval() # Use CPU
|
16 |
|
17 |
# Define folders for uploads and results
|
@@ -75,21 +73,6 @@ def cleanup_old_files():
|
|
75 |
# Streamlit App
|
76 |
st.set_page_config(page_title="GOT-OCR-2.0 Demo", layout="wide")
|
77 |
|
78 |
-
st.markdown("""
|
79 |
-
<h2> <span style="color: #ff6600">General OCR Theory</span>: Towards OCR-2.0 via a Unified End-to-end Model</h2>
|
80 |
-
<a href="https://huggingface.co/ucaslcl/GOT-OCR2_0">[😊 Hugging Face]</a>
|
81 |
-
<a href="https://arxiv.org/abs/2409.01704">[📜 Paper]</a>
|
82 |
-
<a href="https://github.com/Ucas-HaoranWei/GOT-OCR2.0/">[🌟 GitHub]</a>
|
83 |
-
""", unsafe_allow_html=True)
|
84 |
-
|
85 |
-
st.markdown("""
|
86 |
-
"🔥🔥🔥This is the official online demo of the GOT-OCR-2.0 model!!!"
|
87 |
-
### Demo Guidelines
|
88 |
-
- You need to upload your image below and choose one mode of GOT, then click "Submit" to run the GOT model. More characters will result in longer wait times.
|
89 |
-
- **plain texts OCR & format texts OCR**: The two modes are for the image-level OCR.
|
90 |
-
- **plain multi-crop OCR & format multi-crop OCR**: For images with more complex content, you can achieve higher-quality results with these modes.
|
91 |
-
- **plain fine-grained OCR & format fine-grained OCR**: In these modes, you can specify fine-grained regions on the input image for more flexible OCR. Fine-grained regions can be coordinates of the box, red color, blue color, or green color.
|
92 |
-
""")
|
93 |
|
94 |
uploaded_image = st.file_uploader("Upload your image", type=["png", "jpg", "jpeg"])
|
95 |
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModel, AutoTokenizer
|
3 |
from PIL import Image
|
|
|
5 |
import base64
|
6 |
import uuid
|
7 |
import time
|
|
|
8 |
from pathlib import Path
|
9 |
|
10 |
# Load tokenizer and model on CPU
|
11 |
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
12 |
+
model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True).to("cpu")
|
13 |
model = model.eval() # Use CPU
|
14 |
|
15 |
# Define folders for uploads and results
|
|
|
73 |
# Streamlit App
|
74 |
st.set_page_config(page_title="GOT-OCR-2.0 Demo", layout="wide")
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
uploaded_image = st.file_uploader("Upload your image", type=["png", "jpg", "jpeg"])
|
78 |
|