datasaur-dev commited on
Commit
2096cd3
·
verified ·
1 Parent(s): 822fa11

Create app.py

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