Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -821,33 +821,26 @@ def run_pipeline(file: Optional[gr.File], raw_txt: Optional[str]) -> str:
|
|
| 821 |
return f"OCR pipeline error: {e}"
|
| 822 |
|
| 823 |
|
|
|
|
| 824 |
# ---------- Gradio UI ----------
|
| 825 |
TITLE = "docTR OCR — Text Extractor"
|
| 826 |
DESC = (
|
| 827 |
-
"Upload an image or PDF
|
| 828 |
-
"and returns plain text per page. CPU-friendly and ready for enterprise prototyping."
|
| 829 |
)
|
| 830 |
|
| 831 |
with gr.Blocks(theme="soft", title=TITLE) as demo:
|
| 832 |
gr.Markdown(f"# {TITLE}\n{DESC}")
|
| 833 |
|
| 834 |
-
with gr.
|
| 835 |
-
|
| 836 |
-
gr.TabItem("Upload File"),
|
| 837 |
-
gr.TabItem("Paste Raw Text")
|
| 838 |
-
],
|
| 839 |
-
tab_names=["Upload File", "Paste Raw Text"]
|
| 840 |
-
) as tabs:
|
| 841 |
-
with tabs.children[0]:
|
| 842 |
inp = gr.File(
|
| 843 |
label="Upload image/PDF",
|
| 844 |
-
file_types=[".png", ".jpg", ".jpeg", ".tif", ".tiff",
|
| 845 |
)
|
| 846 |
-
#
|
| 847 |
raw_txt_hidden = gr.Textbox(visible=False)
|
| 848 |
|
| 849 |
-
with
|
| 850 |
-
# expose text lane; hide file lane counterpart
|
| 851 |
raw_txt = gr.Textbox(
|
| 852 |
label="Paste raw invoice text (we’ll map directly to JSON schema)",
|
| 853 |
lines=18,
|
|
@@ -866,14 +859,10 @@ with gr.Blocks(theme="soft", title=TITLE) as demo:
|
|
| 866 |
)
|
| 867 |
|
| 868 |
gr.Markdown(
|
| 869 |
-
"ℹ️ **Usage:** Prefer
|
| 870 |
-
"If both file and text are provided, we’ll **prioritize the pasted text
|
| 871 |
)
|
| 872 |
|
| 873 |
if __name__ == "__main__":
|
| 874 |
-
demo.launch(
|
| 875 |
-
|
| 876 |
-
server_port=7860,
|
| 877 |
-
share=True,
|
| 878 |
-
show_error=True
|
| 879 |
-
)
|
|
|
|
| 821 |
return f"OCR pipeline error: {e}"
|
| 822 |
|
| 823 |
|
| 824 |
+
# ---------- Gradio UI ----------
|
| 825 |
# ---------- Gradio UI ----------
|
| 826 |
TITLE = "docTR OCR — Text Extractor"
|
| 827 |
DESC = (
|
| 828 |
+
"Upload an image or PDF OR paste raw text. Uses docTR for OCR or directly maps raw text to the invoice JSON schema."
|
|
|
|
| 829 |
)
|
| 830 |
|
| 831 |
with gr.Blocks(theme="soft", title=TITLE) as demo:
|
| 832 |
gr.Markdown(f"# {TITLE}\n{DESC}")
|
| 833 |
|
| 834 |
+
with gr.Tabs():
|
| 835 |
+
with gr.Tab("Upload File"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
inp = gr.File(
|
| 837 |
label="Upload image/PDF",
|
| 838 |
+
file_types=[".png", ".jpg", ".jpeg", ".tif", ".tiff", ".pdf"]
|
| 839 |
)
|
| 840 |
+
# keep symmetrical inputs for single-click wiring
|
| 841 |
raw_txt_hidden = gr.Textbox(visible=False)
|
| 842 |
|
| 843 |
+
with gr.Tab("Paste Raw Text"):
|
|
|
|
| 844 |
raw_txt = gr.Textbox(
|
| 845 |
label="Paste raw invoice text (we’ll map directly to JSON schema)",
|
| 846 |
lines=18,
|
|
|
|
| 859 |
)
|
| 860 |
|
| 861 |
gr.Markdown(
|
| 862 |
+
"ℹ️ **Usage:** Prefer *Paste Raw Text* when you already have text. "
|
| 863 |
+
"If both file and text are provided, we’ll **prioritize the pasted text**."
|
| 864 |
)
|
| 865 |
|
| 866 |
if __name__ == "__main__":
|
| 867 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True, show_error=True)
|
| 868 |
+
|
|
|
|
|
|
|
|
|
|
|
|