Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -671,43 +671,19 @@ def process_invoice(pdf_file):
|
|
| 671 |
|
| 672 |
return "\n".join(output)
|
| 673 |
|
| 674 |
-
def gradio_interface(pdf_file
|
| 675 |
"""Gradio interface to process uploaded PDF and display structured results."""
|
| 676 |
-
if session_state is None:
|
| 677 |
-
session_state = gr.State({"logged_in": True})
|
| 678 |
-
|
| 679 |
-
if not session_state["logged_in"]:
|
| 680 |
-
return "You have been logged out. Please log in again.", session_state
|
| 681 |
-
|
| 682 |
if pdf_file is None:
|
| 683 |
-
return "Please upload a PDF file."
|
| 684 |
-
|
| 685 |
result = process_invoice(pdf_file)
|
| 686 |
-
return result
|
| 687 |
-
|
| 688 |
-
def logout(session_state):
|
| 689 |
-
"""Handle logout by updating session state and returning login page message."""
|
| 690 |
-
session_state["logged_in"] = False
|
| 691 |
-
return "You have been logged out. Please log in again.", session_state
|
| 692 |
|
| 693 |
with gr.Blocks(css=".prose a[href*='share']:has(svg) {display:none !important;}") as iface:
|
| 694 |
-
session_state = gr.State({"logged_in": True})
|
| 695 |
gr.Markdown("# Invoice Fraud Detection")
|
| 696 |
with gr.Row():
|
| 697 |
file_input = gr.File(label="Upload Invoice PDF")
|
| 698 |
result_output = gr.Markdown(label="Fraud Detection Results")
|
| 699 |
-
|
| 700 |
|
| 701 |
-
file_input.change(
|
| 702 |
-
fn=gradio_interface,
|
| 703 |
-
inputs=[file_input, session_state],
|
| 704 |
-
outputs=[result_output, session_state]
|
| 705 |
-
)
|
| 706 |
-
logout_button.click(
|
| 707 |
-
fn=logout,
|
| 708 |
-
inputs=session_state,
|
| 709 |
-
outputs=[result_output, session_state]
|
| 710 |
-
)
|
| 711 |
-
|
| 712 |
if __name__ == "__main__":
|
| 713 |
iface.launch()
|
|
|
|
| 671 |
|
| 672 |
return "\n".join(output)
|
| 673 |
|
| 674 |
+
def gradio_interface(pdf_file):
|
| 675 |
"""Gradio interface to process uploaded PDF and display structured results."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
if pdf_file is None:
|
| 677 |
+
return "Please upload a PDF file."
|
|
|
|
| 678 |
result = process_invoice(pdf_file)
|
| 679 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
|
| 681 |
with gr.Blocks(css=".prose a[href*='share']:has(svg) {display:none !important;}") as iface:
|
|
|
|
| 682 |
gr.Markdown("# Invoice Fraud Detection")
|
| 683 |
with gr.Row():
|
| 684 |
file_input = gr.File(label="Upload Invoice PDF")
|
| 685 |
result_output = gr.Markdown(label="Fraud Detection Results")
|
| 686 |
+
file_input.change(fn=gradio_interface, inputs=file_input, outputs=result_output)
|
| 687 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
if __name__ == "__main__":
|
| 689 |
iface.launch()
|