Update app.py
Browse files
app.py
CHANGED
|
@@ -3,27 +3,6 @@ import re
|
|
| 3 |
from reportlab.lib.pagesizes import letter
|
| 4 |
from reportlab.pdfgen import canvas
|
| 5 |
import bleach
|
| 6 |
-
from simple_salesforce import Salesforce, SalesforceError
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
-
# Salesforce configuration (loaded from environment variables for security)
|
| 10 |
-
SF_USERNAME = os.getenv("SF_USERNAME")
|
| 11 |
-
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
| 12 |
-
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
|
| 13 |
-
SF_INSTANCE_URL = os.getenv("SF_INSTANCE_URL")
|
| 14 |
-
|
| 15 |
-
# Initialize Salesforce connection
|
| 16 |
-
def init_salesforce():
|
| 17 |
-
try:
|
| 18 |
-
sf = Salesforce(
|
| 19 |
-
username=SF_USERNAME,
|
| 20 |
-
password=SF_PASSWORD,
|
| 21 |
-
security_token=SF_SECURITY_TOKEN,
|
| 22 |
-
instance_url=SF_INSTANCE_URL
|
| 23 |
-
)
|
| 24 |
-
return sf, "Salesforce connected successfully"
|
| 25 |
-
except SalesforceError as e:
|
| 26 |
-
return None, f"Salesforce connection failed: {str(e)}"
|
| 27 |
|
| 28 |
# Clean input to prevent injection attacks
|
| 29 |
def sanitize_input(text):
|
|
@@ -83,32 +62,6 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 83 |
|
| 84 |
return score, checklist_summary, missing_summary, status, progress_bar
|
| 85 |
|
| 86 |
-
# Create Salesforce record using Case object
|
| 87 |
-
def create_salesforce_record(score, checklist_summary, missing_summary, status):
|
| 88 |
-
sf, connection_message = init_salesforce()
|
| 89 |
-
if not sf:
|
| 90 |
-
# Since there's no UI output, silently fail (or log if needed)
|
| 91 |
-
return
|
| 92 |
-
|
| 93 |
-
# Map app status to Salesforce Case.Status values
|
| 94 |
-
sf_status = "New" # Default for Pending and Escalated
|
| 95 |
-
if status == "Completed":
|
| 96 |
-
sf_status = "Closed"
|
| 97 |
-
|
| 98 |
-
try:
|
| 99 |
-
# Create a Case record in Salesforce with required fields
|
| 100 |
-
record = {
|
| 101 |
-
"Subject": "Project Readiness Evaluation",
|
| 102 |
-
"Description": f"Readiness Score: {score}%\nChecklist Summary:\n{checklist_summary}\nMissing Items: {missing_summary}",
|
| 103 |
-
"Status": sf_status,
|
| 104 |
-
"Origin": "Web", # Required field in many Salesforce orgs
|
| 105 |
-
"Priority": "Medium" # Required field in many Salesforce orgs
|
| 106 |
-
}
|
| 107 |
-
sf.Case.create(record)
|
| 108 |
-
except SalesforceError:
|
| 109 |
-
# Silently fail since there's no UI output to display the error
|
| 110 |
-
pass
|
| 111 |
-
|
| 112 |
# Generate PDF report
|
| 113 |
def generate_pdf(score, checklist_summary, missing_summary, status):
|
| 114 |
pdf_file = "readiness_report.pdf"
|
|
@@ -135,7 +88,7 @@ with gr.Blocks(css="""progress { background-color: #f0f0f0; } .red { background-
|
|
| 135 |
gr.Markdown(
|
| 136 |
"""
|
| 137 |
# Project Closure Readiness Evaluator
|
| 138 |
-
Evaluate project readiness and
|
| 139 |
"""
|
| 140 |
)
|
| 141 |
with gr.Row():
|
|
@@ -160,13 +113,6 @@ with gr.Blocks(css="""progress { background-color: #f0f0f0; } .red { background-
|
|
| 160 |
outputs=[score_output, checklist_output, missing_output, status_output, progress_output]
|
| 161 |
)
|
| 162 |
|
| 163 |
-
# Connect Salesforce create button to create_salesforce_record
|
| 164 |
-
sf_create_btn.click(
|
| 165 |
-
fn=create_salesforce_record,
|
| 166 |
-
inputs=[score_output, checklist_output, missing_output, status_output],
|
| 167 |
-
outputs=None # No output since Salesforce Status is removed
|
| 168 |
-
)
|
| 169 |
-
|
| 170 |
# Connect PDF button to generate_pdf
|
| 171 |
pdf_btn.click(
|
| 172 |
fn=generate_pdf,
|
|
|
|
| 3 |
from reportlab.lib.pagesizes import letter
|
| 4 |
from reportlab.pdfgen import canvas
|
| 5 |
import bleach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Clean input to prevent injection attacks
|
| 8 |
def sanitize_input(text):
|
|
|
|
| 62 |
|
| 63 |
return score, checklist_summary, missing_summary, status, progress_bar
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Generate PDF report
|
| 66 |
def generate_pdf(score, checklist_summary, missing_summary, status):
|
| 67 |
pdf_file = "readiness_report.pdf"
|
|
|
|
| 88 |
gr.Markdown(
|
| 89 |
"""
|
| 90 |
# Project Closure Readiness Evaluator
|
| 91 |
+
Evaluate project readiness and generate a PDF report.
|
| 92 |
"""
|
| 93 |
)
|
| 94 |
with gr.Row():
|
|
|
|
| 113 |
outputs=[score_output, checklist_output, missing_output, status_output, progress_output]
|
| 114 |
)
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
# Connect PDF button to generate_pdf
|
| 117 |
pdf_btn.click(
|
| 118 |
fn=generate_pdf,
|