Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from typing import List
|
|
|
|
| 4 |
|
|
|
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
class ReadinessInput(BaseModel):
|
|
@@ -10,21 +13,25 @@ class ReadinessInput(BaseModel):
|
|
| 10 |
punch_list: str
|
| 11 |
|
| 12 |
@app.post("/evaluate")
|
| 13 |
-
async def
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
score = 60
|
| 15 |
missing_items = []
|
| 16 |
|
| 17 |
-
if "complete" in
|
| 18 |
score += 10
|
| 19 |
else:
|
| 20 |
missing_items.append("Project Logs Incomplete")
|
| 21 |
|
| 22 |
-
if
|
| 23 |
score += 20
|
| 24 |
else:
|
| 25 |
missing_items.append("QA Approval Missing")
|
| 26 |
|
| 27 |
-
if "none" in
|
| 28 |
score += 10
|
| 29 |
else:
|
| 30 |
missing_items.append("Open Punch Points Detected")
|
|
@@ -34,8 +41,23 @@ async def evaluate(input: ReadinessInput):
|
|
| 34 |
else "Pending: " + ", ".join(missing_items)
|
| 35 |
)
|
| 36 |
|
| 37 |
-
return
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastapi import FastAPI, Request
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
+
# --- FastAPI setup for Salesforce integration ---
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
class ReadinessInput(BaseModel):
|
|
|
|
| 13 |
punch_list: str
|
| 14 |
|
| 15 |
@app.post("/evaluate")
|
| 16 |
+
async def evaluate_api(input: ReadinessInput):
|
| 17 |
+
return evaluate_readiness(input.logs, input.qa_report, input.punch_list)
|
| 18 |
+
|
| 19 |
+
# --- Gradio logic for browser UI preview ---
|
| 20 |
+
def evaluate_readiness(logs, qa_report, punch_list):
|
| 21 |
score = 60
|
| 22 |
missing_items = []
|
| 23 |
|
| 24 |
+
if "complete" in logs.lower() or "handover done" in logs.lower():
|
| 25 |
score += 10
|
| 26 |
else:
|
| 27 |
missing_items.append("Project Logs Incomplete")
|
| 28 |
|
| 29 |
+
if qa_report.strip().lower() in ["approved", "passed"]:
|
| 30 |
score += 20
|
| 31 |
else:
|
| 32 |
missing_items.append("QA Approval Missing")
|
| 33 |
|
| 34 |
+
if "none" in punch_list.lower() or "resolved" in punch_list.lower():
|
| 35 |
score += 10
|
| 36 |
else:
|
| 37 |
missing_items.append("Open Punch Points Detected")
|
|
|
|
| 41 |
else "Pending: " + ", ".join(missing_items)
|
| 42 |
)
|
| 43 |
|
| 44 |
+
return score, checklist_summary, ", ".join(missing_items) if missing_items else "None"
|
| 45 |
+
|
| 46 |
+
# --- Gradio interface for preview only ---
|
| 47 |
+
demo = gr.Interface(
|
| 48 |
+
fn=evaluate_readiness,
|
| 49 |
+
inputs=[
|
| 50 |
+
gr.Textbox(label="Project Logs"),
|
| 51 |
+
gr.Textbox(label="QA Report"),
|
| 52 |
+
gr.Textbox(label="Punch List (Plain Text)")
|
| 53 |
+
],
|
| 54 |
+
outputs=[
|
| 55 |
+
gr.Number(label="Readiness Score (%)"),
|
| 56 |
+
gr.Textbox(label="Checklist Summary"),
|
| 57 |
+
gr.Textbox(label="Missing Items")
|
| 58 |
+
],
|
| 59 |
+
title="Project Closure Readiness Evaluator"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
demo.queue() # Allows app to work asynchronously
|
| 63 |
+
demo.launch(app=app) # ✅ Attaches FastAPI to Gradio Space
|