Dineshpopuri commited on
Commit
1208fb8
·
verified ·
1 Parent(s): 5fe047a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -41
app.py CHANGED
@@ -5,12 +5,11 @@ from reportlab.pdfgen import canvas
5
  import bleach
6
  import logging
7
  import os
8
- from huggingface_hub import InferenceClient
9
  from retry import retry
10
  import time
11
  from datetime import datetime
12
  import base64
13
- import pytz # Added for proper timezone handling
14
 
15
  # Print statement to confirm script initialization
16
  print("Starting Project Closure Readiness Evaluator app...")
@@ -50,16 +49,6 @@ if not all([SF_USERNAME, SF_PASSWORD, SF_SECURITY_TOKEN, SF_INSTANCE_URL]):
50
  logging.error("Please set these variables in Hugging Face Space Settings > Secrets.")
51
  SALESFORCE_AVAILABLE = False
52
 
53
- # Hugging Face configuration
54
- HF_API_TOKEN = os.getenv("HF_API_TOKEN")
55
- if not HF_API_TOKEN:
56
- logging.error("Hugging Face API token (HF_API_TOKEN) not found. Hugging Face functionality will be disabled.")
57
- logging.error("Please set HF_API_TOKEN in Hugging Face Space Settings > Secrets.")
58
- HF_AVAILABLE = False
59
- else:
60
- HF_AVAILABLE = True
61
- hf_client = InferenceClient(token=HF_API_TOKEN)
62
-
63
  # Initialize Salesforce connection with retry mechanism
64
  @retry(tries=3, delay=2, backoff=2, logger=logger)
65
  def init_salesforce():
@@ -94,26 +83,6 @@ def init_salesforce():
94
  logging.error("Check your Salesforce org settings, network restrictions, or API access.")
95
  raise
96
 
97
- # Summarize text using Hugging Face Inference API
98
- def summarize_text(text, max_length=100, min_length=30):
99
- if not HF_AVAILABLE:
100
- logging.error("Hugging Face API not available. Returning original text.")
101
- return text
102
-
103
- if not text or text == "None":
104
- return "No summary available"
105
-
106
- try:
107
- summary = hf_client.summarization(
108
- text,
109
- model="facebook/bart-large-cnn",
110
- parameters={"max_length": max_length, "min_length": min_length}
111
- )
112
- return summary
113
- except Exception as e:
114
- logging.error(f"Failed to summarize text with Hugging Face: {str(e)}")
115
- return text # Fallback to original text
116
-
117
  # Create Salesforce record in custom object Project_Closure_Handover__c
118
  def create_salesforce_record(project_id, score, checklist_summary, missing_summary, status, escalated, logs, qa_report, punch_list_text, open_punch_items, pdf_path=None):
119
  if not SALESFORCE_AVAILABLE:
@@ -126,16 +95,11 @@ def create_salesforce_record(project_id, score, checklist_summary, missing_summa
126
  logging.error(f"Skipping Salesforce record creation due to connection failure: {connection_message}")
127
  return connection_message
128
 
129
- # Summarize checklist_summary and missing_summary using Hugging Face
130
- summarized_checklist = summarize_text(checklist_summary)
131
- summarized_missing = summarize_text(missing_summary)
132
-
133
  # Ensure inputs are properly formatted
 
134
  score = float(score) if score is not None else 0.0
135
  checklist_summary = str(checklist_summary) if checklist_summary else ""
136
- summarized_checklist = str(summarized_checklist) if summarized_checklist else ""
137
  missing_summary = str(missing_summary) if missing_summary else ""
138
- summarized_missing = str(summarized_missing) if summarized_missing else ""
139
  status = str(status) if status else ""
140
  logs = str(logs) if logs else ""
141
  qa_report = str(qa_report) if qa_report else ""
@@ -152,12 +116,12 @@ def create_salesforce_record(project_id, score, checklist_summary, missing_summa
152
 
153
  # Create the record in Project_Closure_Handover__c without the PDF URL for now
154
  record = {
155
- "Project_ID__c": project_id, # Added Project ID field
156
  "Readiness_Score__c": score,
157
  "Checklist_Summary__c": checklist_summary,
158
  "Missing_Documents__c": missing_documents,
159
  "Status__c": status,
160
- "Summarized_Missing_Items__c": summarized_missing,
161
  "Alert_Sent__c": alert_sent,
162
  "Client_PDF_Pack_URL__c": "", # Will be updated after attachment is created
163
  "Closure_Pack_URL__c": "", # Placeholder; update if you have a closure pack URL
@@ -396,7 +360,7 @@ with gr.Blocks(css="""
396
  )
397
  with gr.Row():
398
  with gr.Column(scale=2):
399
- project_id_input = gr.Textbox(label="Project ID", placeholder="Enter Project ID (e.g., PROJ-12345)") # Added Project ID input
400
  logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
401
  qa_input = gr.Dropdown(
402
  label="QA Report",
 
5
  import bleach
6
  import logging
7
  import os
 
8
  from retry import retry
9
  import time
10
  from datetime import datetime
11
  import base64
12
+ import pytz # For proper timezone handling
13
 
14
  # Print statement to confirm script initialization
15
  print("Starting Project Closure Readiness Evaluator app...")
 
49
  logging.error("Please set these variables in Hugging Face Space Settings > Secrets.")
50
  SALESFORCE_AVAILABLE = False
51
 
 
 
 
 
 
 
 
 
 
 
52
  # Initialize Salesforce connection with retry mechanism
53
  @retry(tries=3, delay=2, backoff=2, logger=logger)
54
  def init_salesforce():
 
83
  logging.error("Check your Salesforce org settings, network restrictions, or API access.")
84
  raise
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  # Create Salesforce record in custom object Project_Closure_Handover__c
87
  def create_salesforce_record(project_id, score, checklist_summary, missing_summary, status, escalated, logs, qa_report, punch_list_text, open_punch_items, pdf_path=None):
88
  if not SALESFORCE_AVAILABLE:
 
95
  logging.error(f"Skipping Salesforce record creation due to connection failure: {connection_message}")
96
  return connection_message
97
 
 
 
 
 
98
  # Ensure inputs are properly formatted
99
+ project_id = str(project_id) if project_id else "" # Project ID is not summarized
100
  score = float(score) if score is not None else 0.0
101
  checklist_summary = str(checklist_summary) if checklist_summary else ""
 
102
  missing_summary = str(missing_summary) if missing_summary else ""
 
103
  status = str(status) if status else ""
104
  logs = str(logs) if logs else ""
105
  qa_report = str(qa_report) if qa_report else ""
 
116
 
117
  # Create the record in Project_Closure_Handover__c without the PDF URL for now
118
  record = {
119
+ "Project_ID__c": project_id, # Project ID field
120
  "Readiness_Score__c": score,
121
  "Checklist_Summary__c": checklist_summary,
122
  "Missing_Documents__c": missing_documents,
123
  "Status__c": status,
124
+ "Summarized_Missing_Items__c": missing_summary, # No summarization applied
125
  "Alert_Sent__c": alert_sent,
126
  "Client_PDF_Pack_URL__c": "", # Will be updated after attachment is created
127
  "Closure_Pack_URL__c": "", # Placeholder; update if you have a closure pack URL
 
360
  )
361
  with gr.Row():
362
  with gr.Column(scale=2):
363
+ project_id_input = gr.Textbox(label="Project ID", placeholder="Enter Project ID (e.g., PROJ-12345)")
364
  logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
365
  qa_input = gr.Dropdown(
366
  label="QA Report",