Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
import os
|
| 2 |
from paddleocr import PaddleOCR
|
| 3 |
-
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
-
import requests
|
| 6 |
import re
|
| 7 |
-
from simple_salesforce import Salesforce
|
| 8 |
import pandas as pd
|
| 9 |
from fuzzywuzzy import process
|
|
|
|
| 10 |
|
| 11 |
# Attribute mappings: readable names to Salesforce API names
|
| 12 |
ATTRIBUTE_MAPPING = {
|
|
@@ -144,7 +142,7 @@ def interact_with_salesforce(mode, entry_type, quantity, attributes):
|
|
| 144 |
if entry_type == "Sales":
|
| 145 |
object_name = "VENKATA_RAMANA_MOTORS__c"
|
| 146 |
field_name = "Quantity__c"
|
| 147 |
-
elif entry_type =="Non-Sales":
|
| 148 |
object_name = "UNBILLING_DATA__c"
|
| 149 |
field_name = "TotalQuantity__c"
|
| 150 |
elif mode == "Exit":
|
|
@@ -221,44 +219,7 @@ def export_to_salesforce(mode, entry_type, quantity, edited_df):
|
|
| 221 |
# Export to Salesforce
|
| 222 |
message = interact_with_salesforce(mode, entry_type, quantity, edited_attributes)
|
| 223 |
|
| 224 |
-
|
| 225 |
-
try:
|
| 226 |
-
sf = Salesforce(
|
| 227 |
-
username=SALESFORCE_USERNAME,
|
| 228 |
-
password=SALESFORCE_PASSWORD,
|
| 229 |
-
security_token=SALESFORCE_SECURITY_TOKEN
|
| 230 |
-
)
|
| 231 |
-
product_name = edited_attributes.get("Product name", "")
|
| 232 |
-
model_name = edited_attributes.get("Model Name", "")
|
| 233 |
-
stage = edited_attributes.get("Stage", "")
|
| 234 |
-
|
| 235 |
-
# Build the query
|
| 236 |
-
query_conditions = []
|
| 237 |
-
if product_name:
|
| 238 |
-
query_conditions.append(f"Productname__c = '{product_name}'")
|
| 239 |
-
if model_name:
|
| 240 |
-
query_conditions.append(f"Model__c = '{model_name}'")
|
| 241 |
-
if stage:
|
| 242 |
-
query_conditions.append(f"Stage__c = '{stage}'")
|
| 243 |
-
|
| 244 |
-
if query_conditions:
|
| 245 |
-
query = f"SELECT Price__c FROM Inventory_Management__c WHERE {' AND '.join(query_conditions)} LIMIT 1"
|
| 246 |
-
response = sf.query(query)
|
| 247 |
-
|
| 248 |
-
if response["records"]:
|
| 249 |
-
price = response["records"][0].get("Price__c", None)
|
| 250 |
-
if price:
|
| 251 |
-
price_message = f"The estimated price for the {product_name} with {model_name} at {stage} is ₹{price:,}."
|
| 252 |
-
return f"{message}\n\n{price_message}"
|
| 253 |
-
else:
|
| 254 |
-
return f"{message}\n\nPrice information not available for the specified product."
|
| 255 |
-
else:
|
| 256 |
-
return f"{message}\n\nNo matching record found for the specified product."
|
| 257 |
-
else:
|
| 258 |
-
return f"{message}\n\nInsufficient data to fetch price information."
|
| 259 |
-
|
| 260 |
-
except Exception as e:
|
| 261 |
-
return f"{message}\n\nError fetching price information: {str(e)}"
|
| 262 |
|
| 263 |
except Exception as e:
|
| 264 |
return f"❌ Error exporting to Salesforce: {str(e)}"
|
|
@@ -293,4 +254,4 @@ def app():
|
|
| 293 |
return demo
|
| 294 |
|
| 295 |
if __name__ == "__main__":
|
| 296 |
-
app().launch(share=True)
|
|
|
|
| 1 |
import os
|
| 2 |
from paddleocr import PaddleOCR
|
|
|
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
import re
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from fuzzywuzzy import process
|
| 7 |
+
from simple_salesforce import Salesforce
|
| 8 |
|
| 9 |
# Attribute mappings: readable names to Salesforce API names
|
| 10 |
ATTRIBUTE_MAPPING = {
|
|
|
|
| 142 |
if entry_type == "Sales":
|
| 143 |
object_name = "VENKATA_RAMANA_MOTORS__c"
|
| 144 |
field_name = "Quantity__c"
|
| 145 |
+
elif entry_type == "Non-Sales":
|
| 146 |
object_name = "UNBILLING_DATA__c"
|
| 147 |
field_name = "TotalQuantity__c"
|
| 148 |
elif mode == "Exit":
|
|
|
|
| 219 |
# Export to Salesforce
|
| 220 |
message = interact_with_salesforce(mode, entry_type, quantity, edited_attributes)
|
| 221 |
|
| 222 |
+
return message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
except Exception as e:
|
| 225 |
return f"❌ Error exporting to Salesforce: {str(e)}"
|
|
|
|
| 254 |
return demo
|
| 255 |
|
| 256 |
if __name__ == "__main__":
|
| 257 |
+
app().launch(share=True)
|