Spaces:
Build error
Build error
Update app.py
Browse files237 unmodified lines2382392402412422432442452464 unmodified lines2512522532542552562572582592602612622632642652662672682692702712722732742754 unmodified lines28028128228328428528646 unmodified lines333334335336337338339340237 unmodified linessecurity_token=SALESFORCE_SECURITY_TOKEN)query_inventory = "SELECT Product_Name__c, Current_Stocks__c, soldstock__c FROM Inventory_Management__c LIMIT 100"query_unbillable= "SELECT Product_Name__c, Current_Stock__c, soldstock__c FROM Un_Billable__c LIMIT 100"response_inventory = sf.query_all(query_inventory)response_unbillable = sf.query_all(query_unbillable)4 unmodified linesif not records_inventory and not records_unbillable:return "No data found in Salesforce.", None, None, Nonerecords = records_inventory + records_unbillabledf = pd.DataFrame(records)df = df.drop(columns=['attributes'], errors='ignore')# Rename columns for better readabilitydf.rename(columns={"Product_Name__c": "Product Name","Modal_Name__c": "Model Name (Inventory)","Model_Name__c": "Model Name (Unbillable)","Current_Stocks__c": "Current Stocks","soldstock__c": "Sold Stock"}, inplace=True)excel_path = "salesforce_data.xlsx"df.to_excel(excel_path, index=False)# Generate interactive vertical bar graph using Matplotlibfig, ax = plt.subplots(figsize=(12, 8))df.plot(kind='bar', x="Product Name", y="Current Stocks", ax=ax, legend=False)ax.set_title("Stock Distribution by Product Name")ax.set_xlabel("Product Name")ax.set_ylabel("Current Stocks")4 unmodified linesbuffer.seek(0)img = Image.open(buffer)return "Data successfully retrieved.", df, excel_path, imgexcept Exception as e:return f"Error fetching data: {str(e)}", None, None, None46 unmodified lines)], ["📥 OCR Processing", "📊 Salesforce Data Export"])if __name__ == "__main__":app().launch(share=True)if __name__ == "__main__":app().launch(share=True)237 unmodified lines2382392402412422432442454 unmodified lines2502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842854 unmodified lines29029129229329429529646 unmodified lines343344345346347237 unmodified linessecurity_token=SALESFORCE_SECURITY_TOKEN)query_inventory = "SELECT Product_Name__c, Modal_Name__c, Current_Stocks__c, soldstock__c FROM Inventory_Management__c LIMIT 100"query_unbillable = "SELECT Product_Name__c, Model_Name__c, Current_Stocks__c, soldstock__c FROM Un_Billable__c LIMIT 100"response_inventory = sf.query_all(query_inventory)response_unbillable = sf.query_all(query_unbillable)4 unmodified linesif not records_inventory and not records_unbillable:return "No data found in Salesforce.", None, None, None# Create separate DataFrames for each objectdf_inventory = pd.DataFrame(records_inventory).drop(columns=['attributes'], errors='ignore')df_unbillable = pd.DataFrame(records_unbillable).drop(columns=['attributes'], errors='ignore')# Rename columns for better readabilitydf_inventory.rename(columns={"Product_Name__c": "Product Name (Inventory)","Modal_Name__c": "Model Name (Inventory)","Current_Stocks__c": "Current Stocks (Inventory)","soldstock__c": "Sold Stock (Inventory)"}, inplace=True)df_unbillable.rename(columns={"Product_Name__c": "Product Name (Unbillable)","Model_Name__c": "Model Name (Unbillable)","Current_Stocks__c": "Current Stocks (Unbillable)","soldstock__c": "Sold Stock (Unbillable)"}, inplace=True)# Combine the DataFrames side by sidedf_combined = pd.concat([df_inventory, df_unbillable], axis=1)excel_path = "salesforce_data.xlsx"df_combined.to_excel(excel_path, index=False)# Generate interactive vertical bar graph using Matplotlibfig, ax = plt.subplots(figsize=(12, 8))width = 0.4 # Width of the barsdf_inventory.plot(kind='bar', x="Product Name (Inventory)", y="Current Stocks (Inventory)", ax=ax, legend=True, color='blue', position=0, width=width)df_unbillable.plot(kind='bar', x="Product Name (Unbillable)", y="Current Stocks (Unbillable)", ax=ax, legend=True, color='red', position=1, width=width)ax.set_title("Stock Distribution by Product Name")ax.set_xlabel("Product Name")ax.set_ylabel("Current Stocks")4 unmodified linesbuffer.seek(0)img = Image.open(buffer)return "Data successfully retrieved.", df_combined, excel_path, imgexcept Exception as e:return f"Error fetching data: {str(e)}", None, None, None46 unmodified lines)], ["📥 OCR Processing", "📊 Salesforce Data Export"])if __name__ == "__main__":app().launch(share=True)
app.py+23-16