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image
|
| 5 |
+
|
| 6 |
+
# Mock DB in memory
|
| 7 |
+
CASES = {}
|
| 8 |
+
|
| 9 |
+
# Required images checklist
|
| 10 |
+
REQUIRED_PHOTOS = [
|
| 11 |
+
"Street View",
|
| 12 |
+
"Front Elevation",
|
| 13 |
+
"Living Room",
|
| 14 |
+
"Kitchen",
|
| 15 |
+
"Bedroom",
|
| 16 |
+
"Bathroom",
|
| 17 |
+
"Document Scan"
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
def engineer_submit(case_name, engineer_name, images):
|
| 21 |
+
case_id = str(uuid.uuid4())[:8]
|
| 22 |
+
uploaded_count = len(images) if images else 0
|
| 23 |
+
completeness = int((uploaded_count / len(REQUIRED_PHOTOS)) * 100)
|
| 24 |
+
|
| 25 |
+
CASES[case_id] = {
|
| 26 |
+
"case_id": case_id,
|
| 27 |
+
"case_name": case_name,
|
| 28 |
+
"engineer": engineer_name,
|
| 29 |
+
"images": images,
|
| 30 |
+
"status": "Submitted to Data Entry",
|
| 31 |
+
"completeness": completeness,
|
| 32 |
+
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
| 33 |
+
"reviewer_status": "Pending",
|
| 34 |
+
"notes": "",
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
return f"Case Created: {case_id}\nCompleteness: {completeness}%"
|
| 38 |
+
|
| 39 |
+
def get_data_entry_cases():
|
| 40 |
+
rows = []
|
| 41 |
+
for cid, data in CASES.items():
|
| 42 |
+
rows.append([cid, data["case_name"], data["engineer"],
|
| 43 |
+
data["status"], f"{data['completeness']}%", data["timestamp"]])
|
| 44 |
+
return rows
|
| 45 |
+
|
| 46 |
+
def data_entry_action(case_id, action, notes):
|
| 47 |
+
if case_id not in CASES:
|
| 48 |
+
return "Case ID not found."
|
| 49 |
+
|
| 50 |
+
if action == "Approve & Send to Reviewer":
|
| 51 |
+
CASES[case_id]["status"] = "Data Entry Completed"
|
| 52 |
+
CASES[case_id]["reviewer_status"] = "Review Pending"
|
| 53 |
+
elif action == "Request Rework":
|
| 54 |
+
CASES[case_id]["status"] = "Rework Requested"
|
| 55 |
+
else:
|
| 56 |
+
return "Invalid Action"
|
| 57 |
+
|
| 58 |
+
CASES[case_id]["notes"] = notes
|
| 59 |
+
return f"Updated Case {case_id} → {CASES[case_id]['status']}"
|
| 60 |
+
|
| 61 |
+
def reviewer_dashboard():
|
| 62 |
+
rows = []
|
| 63 |
+
for cid, data in CASES.items():
|
| 64 |
+
rows.append([cid, data["case_name"], data["engineer"],
|
| 65 |
+
data["status"], data["reviewer_status"]])
|
| 66 |
+
return rows
|
| 67 |
+
|
| 68 |
+
def reviewer_action(case_id, decision):
|
| 69 |
+
if case_id not in CASES:
|
| 70 |
+
return "Invalid Case ID"
|
| 71 |
+
|
| 72 |
+
if decision == "Approve":
|
| 73 |
+
CASES[case_id]["reviewer_status"] = "Approved"
|
| 74 |
+
CASES[case_id]["status"] = "Completed"
|
| 75 |
+
else:
|
| 76 |
+
CASES[case_id]["reviewer_status"] = "Rejected"
|
| 77 |
+
CASES[case_id]["status"] = "Rejected"
|
| 78 |
+
|
| 79 |
+
return f"Reviewer Updated Case {case_id}: {decision}"
|
| 80 |
+
|
| 81 |
+
def mis_dashboard():
|
| 82 |
+
total = len(CASES)
|
| 83 |
+
completed = len([c for c in CASES.values() if c["status"] == "Completed"])
|
| 84 |
+
rework = len([c for c in CASES.values() if c["status"] == "Rework Requested"])
|
| 85 |
+
avg_complete = 0
|
| 86 |
+
if total > 0:
|
| 87 |
+
avg_complete = sum([c["completeness"] for c in CASES.values()]) / total
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
"Total Cases": total,
|
| 91 |
+
"Completed": completed,
|
| 92 |
+
"Rework Cases": rework,
|
| 93 |
+
"Average Completeness": f"{avg_complete:.2f}%",
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
# ---------- UI LAYOUT ----------
|
| 98 |
+
|
| 99 |
+
with gr.Blocks(title="Property Valuation Automation POC") as demo:
|
| 100 |
+
|
| 101 |
+
gr.Markdown("# 🏠 Property Valuation Automation – POC Demo")
|
| 102 |
+
gr.Markdown("Engineer → Data Entry → Reviewer → MIS Dashboard")
|
| 103 |
+
|
| 104 |
+
with gr.Tab("1️⃣ Engineer Panel"):
|
| 105 |
+
case_name = gr.Textbox(label="Case Name")
|
| 106 |
+
engineer_name = gr.Textbox(label="Engineer Name")
|
| 107 |
+
images = gr.File(label="Upload Required Photos", file_count="multiple", type="filepath")
|
| 108 |
+
|
| 109 |
+
submit_btn = gr.Button("Submit Case")
|
| 110 |
+
eng_output = gr.Textbox(label="Output")
|
| 111 |
+
|
| 112 |
+
submit_btn.click(engineer_submit, [case_name, engineer_name, images], eng_output)
|
| 113 |
+
|
| 114 |
+
with gr.Tab("2️⃣ Data Entry Panel"):
|
| 115 |
+
data_table = gr.DataFrame(headers=["Case ID","Case Name","Engineer","Status","Completeness","Timestamp"],
|
| 116 |
+
label="Cases", interactive=False)
|
| 117 |
+
|
| 118 |
+
refresh_btn = gr.Button("Refresh List")
|
| 119 |
+
refresh_btn.click(get_data_entry_cases, None, data_table)
|
| 120 |
+
|
| 121 |
+
with gr.Row():
|
| 122 |
+
case_id_input = gr.Textbox(label="Case ID")
|
| 123 |
+
action = gr.Radio(["Approve & Send to Reviewer", "Request Rework"], label="Action")
|
| 124 |
+
notes = gr.Textbox(label="Notes")
|
| 125 |
+
update_btn = gr.Button("Update Status")
|
| 126 |
+
data_entry_output = gr.Textbox(label="Response")
|
| 127 |
+
|
| 128 |
+
update_btn.click(data_entry_action, [case_id_input, action, notes], data_entry_output)
|
| 129 |
+
|
| 130 |
+
with gr.Tab("3️⃣ Reviewer Panel"):
|
| 131 |
+
reviewer_table = gr.DataFrame(headers=["Case ID","Case Name","Engineer","Status","Review Status"],
|
| 132 |
+
label="Cases", interactive=False)
|
| 133 |
+
|
| 134 |
+
refresh_review = gr.Button("Refresh Reviewer Queue")
|
| 135 |
+
refresh_review.click(reviewer_dashboard, None, reviewer_table)
|
| 136 |
+
|
| 137 |
+
with gr.Row():
|
| 138 |
+
reviewer_case = gr.Textbox(label="Case ID")
|
| 139 |
+
review_decision = gr.Radio(["Approve", "Reject"], label="Decision")
|
| 140 |
+
review_btn = gr.Button("Submit Review")
|
| 141 |
+
review_output = gr.Textbox(label="Output")
|
| 142 |
+
|
| 143 |
+
review_btn.click(reviewer_action, [reviewer_case, review_decision], review_output)
|
| 144 |
+
|
| 145 |
+
with gr.Tab("4️⃣ MIS Dashboard"):
|
| 146 |
+
mis_out = gr.JSON(label="MIS Summary")
|
| 147 |
+
mis_refresh_btn = gr.Button("Refresh MIS")
|
| 148 |
+
mis_refresh_btn.click(mis_dashboard, None, mis_out)
|
| 149 |
+
|
| 150 |
+
demo.launch()
|