Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Salesforce API endpoint and authentication
|
5 |
+
SALESFORCE_API_URL = "https://your-instance.salesforce.com/services/apexrest/UserHandler/"
|
6 |
+
AUTH_TOKEN = "Your_Auth_Token"
|
7 |
+
|
8 |
+
# Helper function for Salesforce API calls
|
9 |
+
def call_salesforce_api(endpoint, payload):
|
10 |
+
headers = {
|
11 |
+
"Authorization": f"Bearer {AUTH_TOKEN}",
|
12 |
+
"Content-Type": "application/json",
|
13 |
+
}
|
14 |
+
response = requests.post(SALESFORCE_API_URL + endpoint, json=payload, headers=headers)
|
15 |
+
return response.json()
|
16 |
+
|
17 |
+
# Signup function
|
18 |
+
def signup(name, phone, email, password):
|
19 |
+
payload = {"name": name, "email": email, "phone": phone, "password": password}
|
20 |
+
result = call_salesforce_api("registerUser", payload)
|
21 |
+
if result == "Signup successful":
|
22 |
+
return gr.update(visible=False), gr.update(visible=True), "Signup successful! Please login."
|
23 |
+
return None, None, result
|
24 |
+
|
25 |
+
# Login function
|
26 |
+
def login(email, password):
|
27 |
+
payload = {"email": email, "password": password}
|
28 |
+
valid = call_salesforce_api("validateLogin", payload)
|
29 |
+
if valid:
|
30 |
+
return gr.update(visible=False), gr.update(visible=True), "Login successful!"
|
31 |
+
return None, None, "Invalid credentials. Please try again."
|
32 |
+
|
33 |
+
# Gradio app components
|
34 |
+
with gr.Blocks() as app:
|
35 |
+
with gr.Row(visible=True) as login_page:
|
36 |
+
gr.Textbox(label="Email", placeholder="Enter your email", key="login_email")
|
37 |
+
gr.Textbox(label="Password", placeholder="Enter your password", type="password", key="login_password")
|
38 |
+
gr.Button("Login", key="login_button").click(
|
39 |
+
login, inputs=["login_email", "login_password"], outputs=[login_page, "home_page", "message"]
|
40 |
+
)
|
41 |
+
gr.Button("Signup").click(None, [], [login_page, "signup_page"])
|
42 |
+
|
43 |
+
with gr.Row(visible=False) as signup_page:
|
44 |
+
gr.Textbox(label="Name", placeholder="Enter your name", key="signup_name")
|
45 |
+
gr.Textbox(label="Phone", placeholder="Enter your phone number", key="signup_phone")
|
46 |
+
gr.Textbox(label="Email", placeholder="Enter your email", key="signup_email")
|
47 |
+
gr.Textbox(label="Password", placeholder="Enter your password", type="password", key="signup_password")
|
48 |
+
gr.Button("Sign Up", key="signup_button").click(
|
49 |
+
signup, inputs=["signup_name", "signup_phone", "signup_email", "signup_password"], outputs=[signup_page, "login_page", "message"]
|
50 |
+
)
|
51 |
+
gr.Button("Back to Login").click(None, [], [signup_page, "login_page"])
|
52 |
+
|
53 |
+
with gr.Row(visible=False) as home_page:
|
54 |
+
gr.Label(value="Welcome to the Home Page!")
|
55 |
+
gr.Button("Logout").click(None, [], [home_page, "login_page"])
|
56 |
+
|
57 |
+
gr.Label(value="", key="message")
|
58 |
+
|
59 |
+
app.launch()
|