Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
|
|
| 1 |
import requests
|
| 2 |
|
| 3 |
-
# Salesforce
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
| 12 |
def get_salesforce_access_token():
|
| 13 |
payload = {
|
| 14 |
'grant_type': 'password',
|
| 15 |
-
'client_id':
|
| 16 |
-
'client_secret':
|
| 17 |
-
'username':
|
| 18 |
-
'password':
|
| 19 |
}
|
| 20 |
-
response = requests.post(
|
| 21 |
if response.status_code == 200:
|
| 22 |
data = response.json()
|
| 23 |
return data['access_token'], data['instance_url']
|
| 24 |
else:
|
| 25 |
-
raise Exception(f"
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
access_token, instance_url = get_salesforce_access_token()
|
| 29 |
headers = {
|
|
@@ -32,28 +35,34 @@ def get_salesforce_access_token():
|
|
| 32 |
}
|
| 33 |
payload = {
|
| 34 |
'FirstName': name,
|
| 35 |
-
'LastName': 'Customer', # Placeholder
|
| 36 |
'Email': email,
|
| 37 |
'Phone': phone,
|
| 38 |
}
|
| 39 |
url = f"https://huggingface.co/spaces/nagasurendra/DynamicMenu1"
|
| 40 |
response = requests.post(url, headers=headers, json=payload)
|
|
|
|
| 41 |
if response.status_code == 201:
|
| 42 |
-
return "Customer
|
| 43 |
else:
|
| 44 |
-
return f"Failed to
|
| 45 |
except Exception as e:
|
| 46 |
return str(e)
|
| 47 |
-
def collect_data(name, email, phone):
|
| 48 |
-
return insert_customer(name, email, phone)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
interface = gr.Interface(
|
| 51 |
-
fn=
|
| 52 |
-
inputs=["text", "text", "text"],
|
| 53 |
outputs="text",
|
| 54 |
-
title="Customer
|
| 55 |
-
description="Enter your details to save them in Salesforce."
|
| 56 |
)
|
| 57 |
|
|
|
|
| 58 |
interface.launch()
|
| 59 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# Salesforce credentials
|
| 5 |
+
USERNAME = "geethareddy@sathkrutha.com"
|
| 6 |
+
PASSWORD = "7995604808g@"
|
| 7 |
+
SECURITY_TOKEN = "HIi7RyLwaqfYvvTLZvxrU8pU"
|
| 8 |
+
CONSUMER_KEY = "3MVG9GCMQoQ6rpzTiMF88fek3a99fPGaUP5aFXq.xKM6n2f.0asc.KLaQW4umn7PFXK55bh5HvD7lzN5NcHiV"
|
| 9 |
+
CONSUMER_SECRET = C179C90625128C9B88C0275ED439E534CACE39CC129AB1977698C934583C7353
|
| 10 |
+
LOGIN_URL = "https://login.salesforce.com/?locale=in"
|
| 11 |
|
| 12 |
+
# Function to get Salesforce Access Token
|
| 13 |
def get_salesforce_access_token():
|
| 14 |
payload = {
|
| 15 |
'grant_type': 'password',
|
| 16 |
+
'client_id': CONSUMER_KEY,
|
| 17 |
+
'client_secret': CONSUMER_SECRET,
|
| 18 |
+
'username': USERNAME,
|
| 19 |
+
'password': PASSWORD + SECURITY_TOKEN,
|
| 20 |
}
|
| 21 |
+
response = requests.post(LOGIN_URL, data=payload)
|
| 22 |
if response.status_code == 200:
|
| 23 |
data = response.json()
|
| 24 |
return data['access_token'], data['instance_url']
|
| 25 |
else:
|
| 26 |
+
raise Exception(f"Authentication failed: {response.json()}")
|
| 27 |
+
|
| 28 |
+
# Function to save customer details to Salesforce
|
| 29 |
+
def save_customer_to_salesforce(name, email, phone):
|
| 30 |
try:
|
| 31 |
access_token, instance_url = get_salesforce_access_token()
|
| 32 |
headers = {
|
|
|
|
| 35 |
}
|
| 36 |
payload = {
|
| 37 |
'FirstName': name,
|
| 38 |
+
'LastName': 'Customer', # Placeholder for last name
|
| 39 |
'Email': email,
|
| 40 |
'Phone': phone,
|
| 41 |
}
|
| 42 |
url = f"https://huggingface.co/spaces/nagasurendra/DynamicMenu1"
|
| 43 |
response = requests.post(url, headers=headers, json=payload)
|
| 44 |
+
|
| 45 |
if response.status_code == 201:
|
| 46 |
+
return "Customer details saved successfully!"
|
| 47 |
else:
|
| 48 |
+
return f"Failed to save details: {response.json()}"
|
| 49 |
except Exception as e:
|
| 50 |
return str(e)
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
# Gradio interface to collect customer details
|
| 53 |
+
def submit_form(name, email, phone):
|
| 54 |
+
if not name or not email or not phone:
|
| 55 |
+
return "All fields are required."
|
| 56 |
+
return save_customer_to_salesforce(name, email, phone)
|
| 57 |
+
|
| 58 |
+
# Create the Gradio interface
|
| 59 |
interface = gr.Interface(
|
| 60 |
+
fn=submit_form,
|
| 61 |
+
inputs=["text", "text", "text"], # Fields: Name, Email, Phone
|
| 62 |
outputs="text",
|
| 63 |
+
title="Customer Login Page",
|
| 64 |
+
description="Enter your details to save them in Salesforce CRM."
|
| 65 |
)
|
| 66 |
|
| 67 |
+
# Launch the app
|
| 68 |
interface.launch()
|
|
|