Spaces:
Runtime error
Runtime error
Add LoginButton
Browse files
app.py
CHANGED
|
@@ -90,7 +90,28 @@ import spaces
|
|
| 90 |
|
| 91 |
input_image_palette = []
|
| 92 |
current_prerendered_image = gr.State("./images/Beeuty-1.png")
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
#---if workspace = local or colab---
|
| 95 |
|
| 96 |
# Authenticate with Hugging Face
|
|
@@ -858,6 +879,13 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
| 858 |
randomize_seed = gr.Checkbox(False, label="Randomize seed",elem_id="rnd_seed_chk")
|
| 859 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True, elem_id="rnd_seed")
|
| 860 |
lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=3, step=0.01, value=1.01)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
with gr.Row():
|
| 862 |
gr.HTML(value=getVersions(), visible=True, elem_id="versions")
|
| 863 |
|
|
|
|
| 90 |
|
| 91 |
input_image_palette = []
|
| 92 |
current_prerendered_image = gr.State("./images/Beeuty-1.png")
|
| 93 |
+
user_info = {
|
| 94 |
+
"username": "guest",
|
| 95 |
+
"session_hash": None,
|
| 96 |
+
"headers": None,
|
| 97 |
+
"client": None,
|
| 98 |
+
"query_params": None,
|
| 99 |
+
"path_params": None,
|
| 100 |
+
"level" : 0
|
| 101 |
+
}
|
| 102 |
+
# Define a function to handle the login button click and retrieve user information.
|
| 103 |
+
def handle_login(request: gr.Request):
|
| 104 |
+
# Extract user information from the request
|
| 105 |
+
user_info = {
|
| 106 |
+
"username": request.username,
|
| 107 |
+
"session_hash": request.session_hash,
|
| 108 |
+
"headers": dict(request.headers),
|
| 109 |
+
"client": request.client,
|
| 110 |
+
"query_params": dict(request.query_params),
|
| 111 |
+
"path_params": dict(request.path_params),
|
| 112 |
+
"level" : (0 if request.username == "guest" else 2)
|
| 113 |
+
}
|
| 114 |
+
return user_info, gr.update(logout_value=f"Logout {user_info['username']} ({user_info['level']})", value=f"Login {user_info['username']} ({user_info['level']})")
|
| 115 |
#---if workspace = local or colab---
|
| 116 |
|
| 117 |
# Authenticate with Hugging Face
|
|
|
|
| 879 |
randomize_seed = gr.Checkbox(False, label="Randomize seed",elem_id="rnd_seed_chk")
|
| 880 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True, elem_id="rnd_seed")
|
| 881 |
lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=3, step=0.01, value=1.01)
|
| 882 |
+
with gr.Row():
|
| 883 |
+
login_button = gr.LoginButton(logout_value=f"Logout({user_info['username']} ({user_info['level']}))", size="md", elem_classes="solid centered", elem_id="hf_login_btn", icon="./assets/favicon.ico")
|
| 884 |
+
# Create a JSON component to display the user information
|
| 885 |
+
user_info_output = gr.JSON(label="User Information:")
|
| 886 |
+
|
| 887 |
+
# Set up the event listener for the login button click
|
| 888 |
+
login_button.click(fn=handle_login, inputs=[], outputs=[user_info_output, login_button])
|
| 889 |
with gr.Row():
|
| 890 |
gr.HTML(value=getVersions(), visible=True, elem_id="versions")
|
| 891 |
|