Create multi_tenant_login.py
Browse files- multi_tenant_login.py +55 -0
multi_tenant_login.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# modules/multi_tenant_login.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Sample data for hospitals and their corresponding users (for demonstration)
|
| 5 |
+
hospital_data = {
|
| 6 |
+
"Hospital A": {
|
| 7 |
+
"users": {
|
| 8 |
+
"user1": "password1",
|
| 9 |
+
"user2": "password2",
|
| 10 |
+
},
|
| 11 |
+
"rules": "Rules specific to Hospital A",
|
| 12 |
+
"treatments": ["Treatment A1", "Treatment A2"],
|
| 13 |
+
"doctors": ["Dr. A1", "Dr. A2"],
|
| 14 |
+
},
|
| 15 |
+
"Hospital B": {
|
| 16 |
+
"users": {
|
| 17 |
+
"user3": "password3",
|
| 18 |
+
"user4": "password4",
|
| 19 |
+
},
|
| 20 |
+
"rules": "Rules specific to Hospital B",
|
| 21 |
+
"treatments": ["Treatment B1", "Treatment B2"],
|
| 22 |
+
"doctors": ["Dr. B1", "Dr. B2"],
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
def authenticate(hospital_name, username, password):
|
| 27 |
+
"""Authenticate the user based on hospital, username, and password."""
|
| 28 |
+
if hospital_name in hospital_data:
|
| 29 |
+
if username in hospital_data[hospital_name]["users"]:
|
| 30 |
+
if hospital_data[hospital_name]["users"][username] == password:
|
| 31 |
+
return (
|
| 32 |
+
f"Welcome {username} to {hospital_name}!\n\n"
|
| 33 |
+
f"Rules: {hospital_data[hospital_name]['rules']}\n"
|
| 34 |
+
f"Available Treatments: {', '.join(hospital_data[hospital_name]['treatments'])}\n"
|
| 35 |
+
f"Doctors: {', '.join(hospital_data[hospital_name]['doctors'])}"
|
| 36 |
+
)
|
| 37 |
+
return "Invalid credentials or hospital name. Please try again."
|
| 38 |
+
|
| 39 |
+
def create_gradio_interface():
|
| 40 |
+
"""Create the Gradio interface for multi-tenant login."""
|
| 41 |
+
hospital_name = gr.Dropdown(choices=list(hospital_data.keys()), label="Select Hospital")
|
| 42 |
+
username = gr.Textbox(label="Username")
|
| 43 |
+
password = gr.Password(label="Password")
|
| 44 |
+
login_button = gr.Button("Login")
|
| 45 |
+
output = gr.Textbox(label="Output", interactive=False)
|
| 46 |
+
|
| 47 |
+
# Set up the login button action
|
| 48 |
+
login_button.click(authenticate, inputs=[hospital_name, username, password], outputs=output)
|
| 49 |
+
|
| 50 |
+
return gr.Interface(
|
| 51 |
+
fn=authenticate,
|
| 52 |
+
inputs=[hospital_name, username, password],
|
| 53 |
+
outputs=output,
|
| 54 |
+
title="Multi-Tenant Login"
|
| 55 |
+
)
|