Spaces:
Build error
Build error
Update app.py
Browse files9 unmodified lines10111213141570 unmodified lines868788899091189 unmodified lines28128228328428528636 unmodified lines3233243253269 unmodified linesfrom io import BytesIOfrom fuzzywuzzy import processimport kaleido # Ensure kaleido is imported# Attribute mappings: readable names to Salesforce API namesATTRIBUTE_MAPPING = {70 unmodified linesSALESFORCE_PASSWORD = "Venkat12345@"SALESFORCE_SECURITY_TOKEN = "GhcJJmjBEefdnukJoz4CAQlR"# Initialize PaddleOCRocr = PaddleOCR(use_angle_cls=True, lang='en')189 unmodified linesexcept Exception as e:return f"Error fetching data: {str(e)}", None, None, None# Gradio Interfacedef app():with gr.Blocks() as demo:36 unmodified linesreturn demoif __name__ == "__main__":app().launch(share=True)9 unmodified lines10111213141516171870 unmodified lines8990919293949596979899100189 unmodified lines29029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035136 unmodified lines3883893903913923933943953963979 unmodified linesfrom io import BytesIOfrom fuzzywuzzy import processimport kaleido # Ensure kaleido is importedimport scheduleimport timefrom twilio.rest import Client# Attribute mappings: readable names to Salesforce API namesATTRIBUTE_MAPPING = {70 unmodified linesSALESFORCE_PASSWORD = "Venkat12345@"SALESFORCE_SECURITY_TOKEN = "GhcJJmjBEefdnukJoz4CAQlR"# Twilio credentialsTWILIO_ACCOUNT_SID = 'AC13c539258acfc3502a91666337ac53c7'TWILIO_AUTH_TOKEN = '00b6ab917fabcdf9632b012528b36079'TWILIO_PHONE_NUMBER = 'whatsapp:+19034027384'WHATSAPP_NUMBER = 'whatsapp:+19034027384'# Initialize PaddleOCRocr = PaddleOCR(use_angle_cls=True, lang='en')189 unmodified linesexcept Exception as e:return f"Error fetching data: {str(e)}", None, None, None# Function to check stock levels and send alerts using Twiliodef check_stock_levels_and_send_alerts():try:sf = Salesforce(username=SALESFORCE_USERNAME,password=SALESFORCE_PASSWORD,security_token=SALESFORCE_SECURITY_TOKEN)# Query Inventory_Management__cinventory_query = "SELECT Productname__c, Current_Stocks__c FROM Inventory_Management__c WHERE Current_Stocks__c < 10"inventory_records = sf.query_all(inventory_query).get("records", [])# Query Un_Billable__cunbillable_query = "SELECT Productname__c, Current_Stock__c FROM Un_Billable__c WHERE Current_Stock__c < 10"unbillable_records = sf.query_all(unbillable_query).get("records", [])client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)for record in inventory_records:product_name = record["Productname__c"]current_stock = record["Current_Stocks__c"]message_body = f"Urgent Stock Alert! The following products have stock levels below 10 and require immediate attention:\n\n" \f"Product Name: {product_name}\n" \f"Current Stock: {current_stock}\n" \f"Please review and restock accordingly.\n\n" \f"Thank you!"client.messages.create(body=message_body,from_=TWILIO_PHONE_NUMBER,to=WHATSAPP_NUMBER)for record in unbillable_records:product_name = record["Productname__c"]current_stock = record["Current_Stock__c"]message_body = f"Urgent Stock Alert! The following products have stock levels below 10 and require immediate attention:\n\n" \f"Product Name: {product_name}\n" \f"Current Stock: {current_stock}\n" \f"Please review and restock accordingly.\n\n" \f"Thank you!"client.messages.create(body=message_body,from_=TWILIO_PHONE_NUMBER,to=WHATSAPP_NUMBER)print("Stock alerts sent successfully.")except Exception as e:print(f"Error checking stock levels and sending alerts: {str(e)}")# Schedule the stock level check every 5 hoursschedule.every(5).hours.do(check_stock_levels_and_send_alerts)# Gradio Interfacedef app():with gr.Blocks() as demo:36 unmodified linesreturn demoif __name__ == "__main__":# Start the Gradio appapp().launch(share=True)# Run the scheduled taskswhile True:schedule.run_pending()time.sleep(1)
app.py+72-1