user_login / app.py
geethareddy's picture
Update app.py
0306dc4 verified
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()