Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,42 @@ import requests
|
|
10 |
def greet(name):
|
11 |
return "Hello " + name + "!"
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
CIMStheme = gr.themes.Soft().set(button_primary_background_fill='#6562F4')
|
14 |
|
15 |
with gr.Blocks(CIMStheme) as demo:
|
@@ -18,4 +54,4 @@ with gr.Blocks(CIMStheme) as demo:
|
|
18 |
greet_btn = gr.Button("Greet")
|
19 |
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
20 |
|
21 |
-
demo.launch(auth=
|
|
|
10 |
def greet(name):
|
11 |
return "Hello " + name + "!"
|
12 |
|
13 |
+
def login_auth(username, password):
|
14 |
+
"""
|
15 |
+
airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{users_table_name}'
|
16 |
+
|
17 |
+
# Query the 'users' table to check for a match with the provided username and password
|
18 |
+
params = {
|
19 |
+
'filterByFormula': f'AND(user_name = "{username}", password = "{password}")'
|
20 |
+
}
|
21 |
+
|
22 |
+
response = requests.get(airtable_endpoint, headers=headers, params=params)
|
23 |
+
|
24 |
+
if response.status_code == 200:
|
25 |
+
data = response.json()
|
26 |
+
#If the matching user/password record is found:
|
27 |
+
if data.get('records'):
|
28 |
+
|
29 |
+
user_details = data['records'][0]['fields']
|
30 |
+
|
31 |
+
log_login(username)
|
32 |
+
|
33 |
+
#Set the global logged_in_user variable. This used in the append_to_at_qalog function to track what user asked the question
|
34 |
+
global logged_in_user,user_user_role, user_output_format, user_school
|
35 |
+
user_user_role = user_details.get('user_role')
|
36 |
+
user_output_format = user_details.get('output_format')
|
37 |
+
user_school = user_details.get('school_name', [None])[0]
|
38 |
+
logged_in_user = username
|
39 |
+
"""
|
40 |
+
if username == password:
|
41 |
+
|
42 |
+
return True
|
43 |
+
|
44 |
+
print(f"Invalid user/password combination")
|
45 |
+
|
46 |
+
return False
|
47 |
+
|
48 |
+
|
49 |
CIMStheme = gr.themes.Soft().set(button_primary_background_fill='#6562F4')
|
50 |
|
51 |
with gr.Blocks(CIMStheme) as demo:
|
|
|
54 |
greet_btn = gr.Button("Greet")
|
55 |
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
|
56 |
|
57 |
+
demo.launch(auth=login_auth,auth_message= "Enter your username and password that you received from CIMS.AI. To request a login, please email 'info@cims.ai'")
|