Skip to content

Commit 3be9b9b

Browse files
Merge pull request #118 from seanpedrick-case/dev
Corrected base href references for FastAPI implementation
2 parents 9ab85e0 + 8c79bfa commit 3be9b9b

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ short_description: OCR / redact PDF documents and tabular data
1111
---
1212
# Document redaction
1313

14-
version: 1.6.6
14+
version: 1.6.7
1515

1616
Redact personally identifiable information (PII) from documents (pdf, png, jpg), Word files (docx), or tabular data (xlsx/csv/parquet). Please see the [User Guide](#user-guide) for a full walkthrough of all the features in the app.
1717

app.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ async def lifespan(app: FastAPI):
300300

301301

302302
# 3. Initialize the App with the lifespan parameter
303-
app = FastAPI(lifespan=lifespan)
303+
# Clean the ROOT_PATH for FastAPI
304+
# Ensure it starts with / and has no trailing /
305+
CLEAN_ROOT = f"/{FASTAPI_ROOT_PATH.strip('/')}" if FASTAPI_ROOT_PATH.strip("/") else ""
306+
app = FastAPI(lifespan=lifespan, root_path=CLEAN_ROOT)
304307

305308
# Added to pass lint check, no effect
306309
spaces.annotations
@@ -521,16 +524,26 @@ async def lifespan(app: FastAPI):
521524
}
522525
"""
523526

524-
# Create the gradio interface
525-
blocks = gr.Blocks(
526-
theme=gr.themes.Default(primary_hue="blue"),
527-
head=head_html,
528-
css=css,
529-
analytics_enabled=False,
530-
title="Document Redaction App",
531-
delete_cache=(43200, 43200), # Temporary file cache deleted every 12 hours
532-
fill_width=True,
533-
)
527+
# Create the gradio interface. If running in FastAPI mode, we don't need the head_html and base_href.
528+
if RUN_FASTAPI:
529+
blocks = gr.Blocks(
530+
theme=gr.themes.Default(primary_hue="blue"),
531+
css=css,
532+
analytics_enabled=False,
533+
title="Document Redaction App",
534+
delete_cache=(43200, 43200), # Temporary file cache deleted every 12 hours
535+
fill_width=True,
536+
)
537+
else:
538+
blocks = gr.Blocks(
539+
theme=gr.themes.Default(primary_hue="blue"),
540+
head=head_html,
541+
css=css,
542+
analytics_enabled=False,
543+
title="Document Redaction App",
544+
delete_cache=(43200, 43200), # Temporary file cache deleted every 12 hours
545+
fill_width=True,
546+
)
534547

535548
with blocks:
536549

@@ -6959,7 +6972,7 @@ def health_check():
69596972
show_error=True,
69606973
auth=authenticate_user if COGNITO_AUTH else None,
69616974
max_file_size=MAX_FILE_SIZE,
6962-
path=FASTAPI_ROOT_PATH,
6975+
path="",
69636976
favicon_path=Path(FAVICON_PATH),
69646977
mcp_server=RUN_MCP_SERVER,
69656978
)

entrypoint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ else
2525
exec uvicorn app:app \
2626
--host $GRADIO_SERVER_NAME \
2727
--port $GRADIO_SERVER_PORT \
28-
--proxy-headers
28+
--proxy-headers \
29+
--forwarded-allow-ips "*"
2930
else
3031
echo "Starting in Gradio mode..."
3132
exec python app.py

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "doc_redaction"
7-
version = "1.6.6"
7+
version = "1.6.7"
88
description = "Redact PDF/image-based documents, Word, or CSV/XLSX files using a Gradio-based GUI interface"
99
readme = "README.md"
1010
authors = [

tools/file_conversion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ def convert_pdf_to_images(
323323
heights = [result[3] for result in results]
324324

325325
print("PDF has been converted to images.")
326-
print("images:", images)
327326
return images, widths, heights, results
328327

329328

0 commit comments

Comments
 (0)