Spaces:
Sleeping
Sleeping
feat: remove temperature parameter from UI and hardcode inference temperature to 0.0
Browse files- LightOnOCR-1B-Demo +1 -1
- hf_space/app.py +9 -16
LightOnOCR-1B-Demo
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
Subproject commit
|
|
|
|
| 1 |
+
Subproject commit 394149f9369a36c1654e32e50356409c68447727
|
hf_space/app.py
CHANGED
|
@@ -55,14 +55,15 @@ def process_pdf(pdf_path, num_pages=1, scale=2.0):
|
|
| 55 |
return images, total_pages
|
| 56 |
|
| 57 |
@spaces.GPU(duration=120) # Increase duration for OCR
|
| 58 |
-
def run_inference(image,
|
| 59 |
"""Run inference on GPU."""
|
| 60 |
global BACKEND
|
| 61 |
if BACKEND is None:
|
| 62 |
load_backend()
|
| 63 |
-
return BACKEND.process_image(image, temperature=
|
| 64 |
|
| 65 |
-
|
|
|
|
| 66 |
"""Process uploaded file with OCR."""
|
| 67 |
if file_input is None:
|
| 68 |
yield "Idle", "Please upload an image or PDF first.", "", "", None
|
|
@@ -71,7 +72,8 @@ def process_input(file_input, scale, temperature, max_tokens, num_pages):
|
|
| 71 |
images_to_process = []
|
| 72 |
page_info = ""
|
| 73 |
display_image = None
|
| 74 |
-
|
|
|
|
| 75 |
file_path = Path(file_input) if isinstance(file_input, str) else Path(file_input.name)
|
| 76 |
if not file_path.exists():
|
| 77 |
yield "Error", f"File not accessible: {file_path}", "", "", None
|
|
@@ -107,8 +109,8 @@ def process_input(file_input, scale, temperature, max_tokens, num_pages):
|
|
| 107 |
for i, img in enumerate(images_to_process):
|
| 108 |
try:
|
| 109 |
print(f"Processing page {i+1}/{len(images_to_process)}...")
|
| 110 |
-
# Run inference on GPU
|
| 111 |
-
text = run_inference(img,
|
| 112 |
all_texts.append(text.strip())
|
| 113 |
|
| 114 |
# Update progress
|
|
@@ -179,15 +181,6 @@ with gr.Blocks(title="📖 LightOnOCR-1B Demo", theme=gr.themes.Soft()) as demo:
|
|
| 179 |
label="PDF Pages",
|
| 180 |
info="Number of pages to process (max 10)"
|
| 181 |
)
|
| 182 |
-
|
| 183 |
-
temperature = gr.Slider(
|
| 184 |
-
minimum=0.0,
|
| 185 |
-
maximum=1.0,
|
| 186 |
-
value=0.1,
|
| 187 |
-
step=0.05,
|
| 188 |
-
label="Temperature",
|
| 189 |
-
info="0 = deterministic"
|
| 190 |
-
)
|
| 191 |
|
| 192 |
page_info = gr.Textbox(
|
| 193 |
label="Processing Info",
|
|
@@ -221,7 +214,7 @@ with gr.Blocks(title="📖 LightOnOCR-1B Demo", theme=gr.themes.Soft()) as demo:
|
|
| 221 |
# Event handlers
|
| 222 |
submit_btn.click(
|
| 223 |
fn=process_input,
|
| 224 |
-
inputs=[file_input, scale_slider,
|
| 225 |
outputs=[status_display, output_text, raw_output, page_info, rendered_image]
|
| 226 |
)
|
| 227 |
|
|
|
|
| 55 |
return images, total_pages
|
| 56 |
|
| 57 |
@spaces.GPU(duration=120) # Increase duration for OCR
|
| 58 |
+
def run_inference(image, max_tokens):
|
| 59 |
"""Run inference on GPU."""
|
| 60 |
global BACKEND
|
| 61 |
if BACKEND is None:
|
| 62 |
load_backend()
|
| 63 |
+
return BACKEND.process_image(image, temperature=0.0, max_tokens=max_tokens)
|
| 64 |
|
| 65 |
+
|
| 66 |
+
def process_input(file_input, scale, max_tokens, num_pages):
|
| 67 |
"""Process uploaded file with OCR."""
|
| 68 |
if file_input is None:
|
| 69 |
yield "Idle", "Please upload an image or PDF first.", "", "", None
|
|
|
|
| 72 |
images_to_process = []
|
| 73 |
page_info = ""
|
| 74 |
display_image = None
|
| 75 |
+
|
| 76 |
+
# ... (rest of image loading logic same as before, simplified for diff clarity)
|
| 77 |
file_path = Path(file_input) if isinstance(file_input, str) else Path(file_input.name)
|
| 78 |
if not file_path.exists():
|
| 79 |
yield "Error", f"File not accessible: {file_path}", "", "", None
|
|
|
|
| 109 |
for i, img in enumerate(images_to_process):
|
| 110 |
try:
|
| 111 |
print(f"Processing page {i+1}/{len(images_to_process)}...")
|
| 112 |
+
# Run inference on GPU (hardcoded temp=0.0)
|
| 113 |
+
text = run_inference(img, max_tokens=max_tokens)
|
| 114 |
all_texts.append(text.strip())
|
| 115 |
|
| 116 |
# Update progress
|
|
|
|
| 181 |
label="PDF Pages",
|
| 182 |
info="Number of pages to process (max 10)"
|
| 183 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
page_info = gr.Textbox(
|
| 186 |
label="Processing Info",
|
|
|
|
| 214 |
# Event handlers
|
| 215 |
submit_btn.click(
|
| 216 |
fn=process_input,
|
| 217 |
+
inputs=[file_input, scale_slider, max_tokens_slider, num_pages],
|
| 218 |
outputs=[status_display, output_text, raw_output, page_info, rendered_image]
|
| 219 |
)
|
| 220 |
|