Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from datetime import datetime
|
|
9 |
from fastapi.responses import HTMLResponse
|
10 |
from simple_salesforce import Salesforce
|
11 |
from dotenv import load_dotenv
|
12 |
-
from datasets import load_dataset
|
13 |
|
14 |
# Load environment variables
|
15 |
load_dotenv()
|
@@ -103,7 +103,7 @@ def fetch_huggingface_records(dataset_name: str = "imdb"):
|
|
103 |
dataset = load_dataset(dataset_name)
|
104 |
logger.info(f"Successfully fetched dataset: {dataset_name}")
|
105 |
records = [record for record in dataset['train']] # Assuming 'train' split
|
106 |
-
return records[:10] # Limit to 10 records
|
107 |
except Exception as e:
|
108 |
logger.error(f"Error fetching Hugging Face dataset {dataset_name}: {str(e)}")
|
109 |
return []
|
@@ -238,7 +238,7 @@ def store_scores_in_salesforce(log: VendorLog, scores: dict, pdf_content: bytes,
|
|
238 |
'Alert_Flag__c': alert_flag
|
239 |
})
|
240 |
score_record_id = score_record['id']
|
241 |
-
logger.info(f"
|
242 |
|
243 |
pdf_base64 = base64.b64encode(pdf_content).decode('utf-8')
|
244 |
content_version = sf.ContentVersion.create({
|
@@ -256,7 +256,7 @@ def store_scores_in_salesforce(log: VendorLog, scores: dict, pdf_content: bytes,
|
|
256 |
|
257 |
pdf_url = f"https://{sf.sf_instance}/sfc/servlet.shepherd/document/download/{content_document_id}"
|
258 |
sf.Subcontractor_Performance_Score__c.update(score_record_id, {'PDF_Link__c': pdf_url})
|
259 |
-
logger.info(f"
|
260 |
except Exception as e:
|
261 |
logger.error(f"Error storing scores in Salesforce: {str(e)}")
|
262 |
raise HTTPException(status_code=500, detail=f"Error storing scores: {str(e)}")
|
@@ -506,4 +506,23 @@ async def get_huggingface_records():
|
|
506 |
|
507 |
@app.get('/debug')
|
508 |
async def debug_info():
|
509 |
-
"""Return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from fastapi.responses import HTMLResponse
|
10 |
from simple_salesforce import Salesforce
|
11 |
from dotenv import load_dotenv
|
12 |
+
from datasets import load_dataset
|
13 |
|
14 |
# Load environment variables
|
15 |
load_dotenv()
|
|
|
103 |
dataset = load_dataset(dataset_name)
|
104 |
logger.info(f"Successfully fetched dataset: {dataset_name}")
|
105 |
records = [record for record in dataset['train']] # Assuming 'train' split
|
106 |
+
return records[:10] # Limit to 10 records
|
107 |
except Exception as e:
|
108 |
logger.error(f"Error fetching Hugging Face dataset {dataset_name}: {str(e)}")
|
109 |
return []
|
|
|
238 |
'Alert_Flag__c': alert_flag
|
239 |
})
|
240 |
score_record_id = score_record['id']
|
241 |
+
logger.info(f"Created Subcontractor_Performance_Score__c record with ID: {score_record_id}")
|
242 |
|
243 |
pdf_base64 = base64.b64encode(pdf_content).decode('utf-8')
|
244 |
content_version = sf.ContentVersion.create({
|
|
|
256 |
|
257 |
pdf_url = f"https://{sf.sf_instance}/sfc/servlet.shepherd/document/download/{content_document_id}"
|
258 |
sf.Subcontractor_Performance_Score__c.update(score_record_id, {'PDF_Link__c': pdf_url})
|
259 |
+
logger.info(f"Updated Subcontractor_Performance_Score__c record with PDF URL: {pdf_url}")
|
260 |
except Exception as e:
|
261 |
logger.error(f"Error storing scores in Salesforce: {str(e)}")
|
262 |
raise HTTPException(status_code=500, detail=f"Error storing scores: {str(e)}")
|
|
|
506 |
|
507 |
@app.get('/debug')
|
508 |
async def debug_info():
|
509 |
+
"""Return debug information about Salesforce and Hugging Face."""
|
510 |
+
try:
|
511 |
+
log_count = sf.query("SELECT COUNT() FROM Vendor_Log__c")['totalSize']
|
512 |
+
fields = [f['name'] for f in sf.Vendor_Log__c.describe()['fields']]
|
513 |
+
score_fields = [f['name'] for f in sf.Subcontractor_Performance_Score__c.describe()['fields']]
|
514 |
+
hf_records = fetch_huggingface_records()
|
515 |
+
return {
|
516 |
+
"salesforce_connected": True,
|
517 |
+
"vendor_log_count": log_count,
|
518 |
+
"vendor_log_fields": fields,
|
519 |
+
"score_fields": score_fields,
|
520 |
+
"huggingface_records_sample": hf_records
|
521 |
+
}
|
522 |
+
except Exception as e:
|
523 |
+
logger.error(f"Debug error: {str(e)}")
|
524 |
+
return {"salesforce_connected": False, "error": str(e)}
|
525 |
+
|
526 |
+
if __name__ == "__main__":
|
527 |
+
import uvicorn
|
528 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|