VaneshDev commited on
Commit
9045d44
·
verified ·
1 Parent(s): 3f82164

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -22,7 +22,6 @@ SALESFORCE_USERNAME = "vaneshdevarapalli866@agentforce.com"
22
  SALESFORCE_PASSWORD = "vanesh@331"
23
  SALESFORCE_SECURITY_TOKEN = "VRUVbBOdG0s9Q4xy0W6DB1Y6b"
24
 
25
- HUGGINGFACE_SPACE_URL = "https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME"
26
  HUGGINGFACE_API_URL = "https://your-huggingface-model-endpoint"
27
 
28
  # Connect to Salesforce
@@ -54,11 +53,11 @@ project_choices = [
54
 
55
  ai_suggestion_choices = ["Move", "Pause Rent", "Repair", "Replace"]
56
 
57
- # Generate PDF and return public Hugging Face URL
58
  def generate_pdf_report(record_id, data_dict):
59
  report_id = str(uuid.uuid4())[:8]
60
  report_filename = f"report_{report_id}.pdf"
61
- report_path = Path(f"static/reports/{report_filename}")
62
  report_path.parent.mkdir(parents=True, exist_ok=True)
63
 
64
  c = canvas.Canvas(str(report_path), pagesize=letter)
@@ -72,7 +71,7 @@ def generate_pdf_report(record_id, data_dict):
72
  y -= 20
73
 
74
  c.save()
75
- return f"{HUGGINGFACE_SPACE_URL}/file/static/reports/{report_filename}", str(report_path)
76
 
77
  def call_ai_model(usage_hours, idle_hours, movement_frequency, cost_per_hour, last_maintenance_str):
78
  try:
@@ -143,9 +142,9 @@ def process_equipment_utilization(equipment_name, project_name, usage_hours, idl
143
  "Utilization Score": utilization_score
144
  }
145
 
146
- public_url, file_path = generate_pdf_report(record_id, summary_data)
147
 
148
- sf.Equipment_Utilization_Record__c.update(record_id, {"Report_Link__c": public_url})
149
 
150
  return {
151
  "Salesforce_Record_Id": record_id,
@@ -153,7 +152,7 @@ def process_equipment_utilization(equipment_name, project_name, usage_hours, idl
153
  "AI_Suggestion": ai_suggestion,
154
  "Suggestion_Confidence": suggestion_confidence,
155
  "Utilization_Score": utilization_score,
156
- "Report_Link": public_url,
157
  "report_file_path": file_path
158
  }
159
  except Exception as e:
@@ -262,4 +261,4 @@ with gr.Blocks() as app:
262
  """
263
 
264
  if __name__ == "__main__":
265
- app.launch()
 
22
  SALESFORCE_PASSWORD = "vanesh@331"
23
  SALESFORCE_SECURITY_TOKEN = "VRUVbBOdG0s9Q4xy0W6DB1Y6b"
24
 
 
25
  HUGGINGFACE_API_URL = "https://your-huggingface-model-endpoint"
26
 
27
  # Connect to Salesforce
 
53
 
54
  ai_suggestion_choices = ["Move", "Pause Rent", "Repair", "Replace"]
55
 
56
+ # Generate PDF and return filename and path
57
  def generate_pdf_report(record_id, data_dict):
58
  report_id = str(uuid.uuid4())[:8]
59
  report_filename = f"report_{report_id}.pdf"
60
+ report_path = Path(f"reports/{report_filename}")
61
  report_path.parent.mkdir(parents=True, exist_ok=True)
62
 
63
  c = canvas.Canvas(str(report_path), pagesize=letter)
 
71
  y -= 20
72
 
73
  c.save()
74
+ return report_filename, str(report_path)
75
 
76
  def call_ai_model(usage_hours, idle_hours, movement_frequency, cost_per_hour, last_maintenance_str):
77
  try:
 
142
  "Utilization Score": utilization_score
143
  }
144
 
145
+ report_filename, file_path = generate_pdf_report(record_id, summary_data)
146
 
147
+ sf.Equipment_Utilization_Record__c.update(record_id, {"Report_Link__c": report_filename})
148
 
149
  return {
150
  "Salesforce_Record_Id": record_id,
 
152
  "AI_Suggestion": ai_suggestion,
153
  "Suggestion_Confidence": suggestion_confidence,
154
  "Utilization_Score": utilization_score,
155
+ "Report_Link": report_filename,
156
  "report_file_path": file_path
157
  }
158
  except Exception as e:
 
261
  """
262
 
263
  if __name__ == "__main__":
264
+ app.launch()