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