Spaces:
Sleeping
Sleeping
File size: 4,118 Bytes
2096cd3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
import gradio as gr
import pandas as pd
import time
# --- Core Application Logic ---
def analyze_wod(file_obj, wod_type):
"""
This function simulates the analysis of a Work Order Document.
In a real application, this is where you would put your PDF parsing,
text extraction, and validation logic.
Args:
file_obj: The uploaded file object from Gradio.
wod_type: The selected type of Work Order Document.
Returns:
A pandas DataFrame with the analysis results.
"""
# Print to console to show the function is running
if file_obj is not None:
print(f"Analyzing '{file_obj.name}' (Type: {wod_type})...")
else:
print(f"Analyzing with no file uploaded (Type: {wod_type})...")
# Simulate a processing delay
time.sleep(2)
# --- Dummy Data Generation ---
# This data simulates the results you would get from a real analysis.
# We include a "Fail" case to demonstrate how it would look.
data = {
"Requirement": [
"Merchant Front Photo",
"EDC Component Photo",
"EDC Placement Photo",
"Terminal Data Verification",
"Timestamped Photos Required",
"Clear Sales Draft",
"Date Consistency Check",
"PIC Signature/Handover",
"BAST/Handover Document",
],
"Reason / Location": [
"Available on Page 2 of the submission.",
"Found in Attachment 1, Photo A.",
"Available on Page 2, second photo.",
"Confirmed on the test transaction receipt, Page 3.",
"Timestamps are visible on all photos on Page 2.",
"Document not found; attachment is missing.",
"Dates on the cover sheet and Page 3 match.",
"Signature is on the Handover Form, Page 4.",
"The BAST is signed and available on Page 4.",
],
"Status": [
"PASS",
"PASS",
"PASS",
"PASS",
"PASS",
"FAIL",
"PASS",
"PASS",
"PASS",
],
}
# Create a pandas DataFrame from the dummy data
df = pd.DataFrame(data)
# Return the DataFrame to be displayed in the Gradio interface
return df
# --- Gradio User Interface Definition ---
# Using gr.Blocks() for a custom layout that matches the elegant design.
with gr.Blocks(
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
css=".gradio-container {max-width: 960px !important; margin: auto !important;}"
) as demo:
# Main Title and Description
gr.Markdown(
"""
# WOD Analyzer
Upload a Work Order Document to automatically check for requirements.
"""
)
# Input Section
with gr.Row():
# File Upload Component
file_input = gr.File(label="Upload WOD PDF")
# Dropdown for WOD Type
type_input = gr.Dropdown(
["REPLACEMENT", "NEW", "MAINTENANCE", "PULL OUT"],
label="Type",
value="REPLACEMENT",
info="Select the type of work order."
)
# Action Button
analyze_btn = gr.Button("Analyze Document", variant="primary")
# Results Section
gr.Markdown("---")
gr.Markdown("## Results")
# DataFrame to display the output, with styling for the 'Status' column
results_output = gr.DataFrame(
headers=["Requirement", "Reason / Location", "Status"],
datatype=["str", "str", "str"],
# This part styles the 'Status' column based on its value
# It applies a green background for 'PASS' and a red one for 'FAIL'
interactive=False,
col_count=(3, "fixed"),
)
# Define the interaction: clicking the button calls the function
analyze_btn.click(
fn=analyze_wod,
inputs=[file_input, type_input],
outputs=[results_output]
)
# --- Launch the Application ---
if __name__ == "__main__":
# The launch() command creates a web server and a public link if needed.
demo.launch()
|