Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -24,17 +24,6 @@ from transformers import (
|
|
24 |
AutoTokenizer,
|
25 |
)
|
26 |
|
27 |
-
# --- Activate Forced Dark Mode ---
|
28 |
-
#js_func = """
|
29 |
-
#function refresh() {
|
30 |
-
# const url = new URL(window.location);
|
31 |
-
# if (url.searchParams.get('__theme') !== 'dark') {
|
32 |
-
# url.searchParams.set('__theme', 'dark');
|
33 |
-
# window.location.href = url.href;
|
34 |
-
# }
|
35 |
-
#}
|
36 |
-
#"""
|
37 |
-
|
38 |
# --- Constants and Model Setup ---
|
39 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
40 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -89,18 +78,6 @@ model_i = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
|
89 |
MODEL_ID_I, trust_remote_code=True, torch_dtype=torch.float16
|
90 |
).to(device).eval()
|
91 |
|
92 |
-
# Load typhoon-ocr-3b
|
93 |
-
MODEL_ID_J = "scb10x/typhoon-ocr-3b"
|
94 |
-
processor_j = AutoProcessor.from_pretrained(
|
95 |
-
MODEL_ID_J,
|
96 |
-
trust_remote_code=True
|
97 |
-
)
|
98 |
-
model_j = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
99 |
-
MODEL_ID_J,
|
100 |
-
trust_remote_code=True,
|
101 |
-
torch_dtype=torch.float16
|
102 |
-
).to(device).eval()
|
103 |
-
|
104 |
# --- Utility Functions ---
|
105 |
def layoutjson2md(layout_data: List[Dict]) -> str:
|
106 |
"""Converts the structured JSON from Layout Analysis into formatted Markdown."""
|
@@ -151,7 +128,6 @@ def process_document_stream(model_name: str, task_choice: str, image: Image.Imag
|
|
151 |
elif model_name == "Nanonets-OCR-s": processor, model = processor_c, model_c
|
152 |
elif model_name == "MonkeyOCR-Recognition": processor, model = processor_g, model_g
|
153 |
elif model_name == "olmOCR-7B-0725": processor, model = processor_i, model_i
|
154 |
-
elif model_name == "typhoon-ocr-3b": processor, model = processor_j, model_j
|
155 |
else:
|
156 |
yield "Invalid model selected.", "Invalid model selected.", None
|
157 |
return
|
@@ -202,7 +178,6 @@ def create_gradio_interface():
|
|
202 |
.process-button { border: none !important; color: white !important; font-weight: bold !important; background-color: blue !important;}
|
203 |
.process-button:hover { background-color: darkblue !important; transform: translateY(-2px) !important; box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important; }
|
204 |
"""
|
205 |
-
#with gr.Blocks(theme="bethecloud/storj_theme", css=css, js=js_func) as demo:
|
206 |
with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
|
207 |
gr.HTML("""
|
208 |
<div class="title" style="text-align: center">
|
@@ -221,8 +196,7 @@ def create_gradio_interface():
|
|
221 |
"MonkeyOCR-Recognition",
|
222 |
"olmOCR-7B-0725",
|
223 |
"Nanonets-OCR-s",
|
224 |
-
"Megalodon-OCR-Sync-0713"
|
225 |
-
"typhoon-ocr-3b"
|
226 |
],
|
227 |
label="Select Model", value="Nanonets-OCR-s"
|
228 |
)
|
@@ -280,4 +254,4 @@ def create_gradio_interface():
|
|
280 |
|
281 |
if __name__ == "__main__":
|
282 |
demo = create_gradio_interface()
|
283 |
-
demo.queue().launch(ssr_mode=False, show_error=True)
|
|
|
24 |
AutoTokenizer,
|
25 |
)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# --- Constants and Model Setup ---
|
28 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
29 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
78 |
MODEL_ID_I, trust_remote_code=True, torch_dtype=torch.float16
|
79 |
).to(device).eval()
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# --- Utility Functions ---
|
82 |
def layoutjson2md(layout_data: List[Dict]) -> str:
|
83 |
"""Converts the structured JSON from Layout Analysis into formatted Markdown."""
|
|
|
128 |
elif model_name == "Nanonets-OCR-s": processor, model = processor_c, model_c
|
129 |
elif model_name == "MonkeyOCR-Recognition": processor, model = processor_g, model_g
|
130 |
elif model_name == "olmOCR-7B-0725": processor, model = processor_i, model_i
|
|
|
131 |
else:
|
132 |
yield "Invalid model selected.", "Invalid model selected.", None
|
133 |
return
|
|
|
178 |
.process-button { border: none !important; color: white !important; font-weight: bold !important; background-color: blue !important;}
|
179 |
.process-button:hover { background-color: darkblue !important; transform: translateY(-2px) !important; box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important; }
|
180 |
"""
|
|
|
181 |
with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
|
182 |
gr.HTML("""
|
183 |
<div class="title" style="text-align: center">
|
|
|
196 |
"MonkeyOCR-Recognition",
|
197 |
"olmOCR-7B-0725",
|
198 |
"Nanonets-OCR-s",
|
199 |
+
"Megalodon-OCR-Sync-0713"
|
|
|
200 |
],
|
201 |
label="Select Model", value="Nanonets-OCR-s"
|
202 |
)
|
|
|
254 |
|
255 |
if __name__ == "__main__":
|
256 |
demo = create_gradio_interface()
|
257 |
+
demo.queue(max_size=40).launch(share=True, mcp_server=True, ssr_mode=False, show_error=True)
|