Spaces:
Running
Running
Create gradio_utils.py
Browse files- gradio_utils.py +22 -0
gradio_utils.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr # Still need this if type hinting gr.Request
|
2 |
+
|
3 |
+
def get_url_user_token(request: gr.Request):
|
4 |
+
"""
|
5 |
+
This function is called when the Gradio app loads.
|
6 |
+
It attempts to retrieve 'user_token' from the URL query parameters.
|
7 |
+
"""
|
8 |
+
user_token_from_url = "user_token not found in URL" # Default message
|
9 |
+
if request:
|
10 |
+
retrieved_token = request.query_params.get("user_token")
|
11 |
+
if retrieved_token:
|
12 |
+
user_token_from_url = retrieved_token
|
13 |
+
print(f"Retrieved user_token from URL: {user_token_from_url}")
|
14 |
+
else:
|
15 |
+
print("user_token key was not found in the URL query parameters.")
|
16 |
+
else:
|
17 |
+
print("Request object not available to get_url_user_token function.")
|
18 |
+
user_token_from_url = "Could not access request object on load"
|
19 |
+
return user_token_from_url
|
20 |
+
|
21 |
+
# You could add other utility functions here in the future
|
22 |
+
|