Spaces:
Sleeping
Sleeping
Divyansh12
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
import streamlit as st
|
3 |
from transformers import AutoModel, AutoTokenizer
|
4 |
from PIL import Image
|
5 |
-
import os
|
6 |
import base64
|
7 |
import uuid
|
8 |
import time
|
@@ -12,10 +11,9 @@ from pathlib import Path
|
|
12 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
13 |
|
14 |
# Load tokenizer and model on CPU
|
15 |
-
|
16 |
tokenizer = AutoTokenizer.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True)
|
17 |
model = AutoModel.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True, use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
|
18 |
-
model
|
19 |
|
20 |
# Define folders for uploads and results
|
21 |
UPLOAD_FOLDER = "./uploads"
|
@@ -80,37 +78,43 @@ st.set_page_config(page_title="GOT-OCR-2.0 Demo", layout="wide")
|
|
80 |
|
81 |
uploaded_image = st.file_uploader("Upload your image", type=["png", "jpg", "jpeg"])
|
82 |
|
|
|
|
|
|
|
83 |
if uploaded_image:
|
84 |
image = Image.open(uploaded_image)
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
"
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
st.
|
|
|
|
|
|
|
114 |
|
115 |
# Cleanup old files
|
116 |
cleanup_old_files()
|
|
|
2 |
import streamlit as st
|
3 |
from transformers import AutoModel, AutoTokenizer
|
4 |
from PIL import Image
|
|
|
5 |
import base64
|
6 |
import uuid
|
7 |
import time
|
|
|
11 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
12 |
|
13 |
# Load tokenizer and model on CPU
|
|
|
14 |
tokenizer = AutoTokenizer.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True)
|
15 |
model = AutoModel.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True, use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
|
16 |
+
model.eval()
|
17 |
|
18 |
# Define folders for uploads and results
|
19 |
UPLOAD_FOLDER = "./uploads"
|
|
|
78 |
|
79 |
uploaded_image = st.file_uploader("Upload your image", type=["png", "jpg", "jpeg"])
|
80 |
|
81 |
+
# Create two columns for layout
|
82 |
+
col1, col2 = st.columns(2)
|
83 |
+
|
84 |
if uploaded_image:
|
85 |
image = Image.open(uploaded_image)
|
86 |
+
|
87 |
+
with col1:
|
88 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
89 |
+
|
90 |
+
with col2:
|
91 |
+
got_mode = st.selectbox("Choose one mode of GOT", [
|
92 |
+
"plain texts OCR",
|
93 |
+
"format texts OCR",
|
94 |
+
"plain multi-crop OCR",
|
95 |
+
"format multi-crop OCR",
|
96 |
+
"plain fine-grained OCR",
|
97 |
+
"format fine-grained OCR",
|
98 |
+
])
|
99 |
+
|
100 |
+
fine_grained_mode = None
|
101 |
+
ocr_color = ""
|
102 |
+
ocr_box = ""
|
103 |
+
|
104 |
+
if "fine-grained" in got_mode:
|
105 |
+
fine_grained_mode = st.selectbox("Fine-grained type", ["box", "color"])
|
106 |
+
if fine_grained_mode == "box":
|
107 |
+
ocr_box = st.text_input("Input box: [x1,y1,x2,y2]", value="[0,0,100,100]")
|
108 |
+
elif fine_grained_mode == "color":
|
109 |
+
ocr_color = st.selectbox("Color list", ["red", "green", "blue"])
|
110 |
+
|
111 |
+
if st.button("Submit"):
|
112 |
+
with st.spinner("Processing..."):
|
113 |
+
result_text, html_result = run_GOT(image, got_mode, fine_grained_mode, ocr_color, ocr_box)
|
114 |
+
st.text_area("GOT Output", result_text, height=200)
|
115 |
+
|
116 |
+
if html_result:
|
117 |
+
st.markdown(html_result, unsafe_allow_html=True)
|
118 |
|
119 |
# Cleanup old files
|
120 |
cleanup_old_files()
|