Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,15 +61,11 @@ def toggle_visibility(is_visible):
|
|
| 61 |
new_icon = "π" if is_visible else "ποΈ"
|
| 62 |
return gr.update(type=new_type), new_icon, not is_visible
|
| 63 |
|
| 64 |
-
# --- NEW DARK MODE TOGGLE LOGIC ---
|
| 65 |
def toggle_dark_mode(current_is_dark):
|
| 66 |
-
# Toggle the boolean state
|
| 67 |
new_state = not current_is_dark
|
| 68 |
-
# Update button label based on the new state
|
| 69 |
new_label = "βοΈ Light Mode" if new_state else "π Dark Mode"
|
| 70 |
return new_label, new_state
|
| 71 |
|
| 72 |
-
# JS to handle the actual CSS class toggle
|
| 73 |
toggle_dark_js = """() => { document.body.classList.toggle('dark'); }"""
|
| 74 |
|
| 75 |
custom_css = """
|
|
@@ -85,20 +81,21 @@ custom_css = """
|
|
| 85 |
.time-display { font-size: 1.5em; font-weight: bold; color: #ff4b4b; }
|
| 86 |
"""
|
| 87 |
|
| 88 |
-
|
|
|
|
| 89 |
gr.Markdown("# π‘οΈ SecurePass Pro Analyzer")
|
| 90 |
|
| 91 |
-
# State variables
|
| 92 |
visible_state = gr.State(True)
|
| 93 |
-
dark_state = gr.State(False)
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
with gr.Column(scale=4):
|
| 97 |
with gr.Row():
|
|
|
|
| 98 |
pass_input = gr.Textbox(
|
| 99 |
label="Enter Password",
|
| 100 |
type="password",
|
| 101 |
-
|
| 102 |
scale=9
|
| 103 |
)
|
| 104 |
show_btn = gr.Button("ποΈ", elem_classes="eye-btn", scale=1)
|
|
@@ -111,15 +108,12 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 111 |
checklist_area = gr.HTML(value=render_checklist("")[0])
|
| 112 |
|
| 113 |
with gr.Row():
|
| 114 |
-
# The button now starts as "Dark Mode"
|
| 115 |
dark_btn = gr.Button("π Dark Mode", variant="secondary")
|
| 116 |
reset_btn = gr.Button("ποΈ Clear", variant="stop")
|
| 117 |
|
| 118 |
-
# Event Handlers
|
| 119 |
pass_input.change(analyze_password, pass_input, [checklist_area, strength_meter, time_output])
|
| 120 |
show_btn.click(toggle_visibility, [visible_state], [pass_input, show_btn, visible_state])
|
| 121 |
|
| 122 |
-
# Dark Mode Handler: Update UI text AND trigger JS
|
| 123 |
dark_btn.click(
|
| 124 |
toggle_dark_mode,
|
| 125 |
inputs=[dark_state],
|
|
@@ -134,4 +128,5 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 134 |
)
|
| 135 |
|
| 136 |
if __name__ == "__main__":
|
| 137 |
-
|
|
|
|
|
|
| 61 |
new_icon = "π" if is_visible else "ποΈ"
|
| 62 |
return gr.update(type=new_type), new_icon, not is_visible
|
| 63 |
|
|
|
|
| 64 |
def toggle_dark_mode(current_is_dark):
|
|
|
|
| 65 |
new_state = not current_is_dark
|
|
|
|
| 66 |
new_label = "βοΈ Light Mode" if new_state else "π Dark Mode"
|
| 67 |
return new_label, new_state
|
| 68 |
|
|
|
|
| 69 |
toggle_dark_js = """() => { document.body.classList.toggle('dark'); }"""
|
| 70 |
|
| 71 |
custom_css = """
|
|
|
|
| 81 |
.time-display { font-size: 1.5em; font-weight: bold; color: #ff4b4b; }
|
| 82 |
"""
|
| 83 |
|
| 84 |
+
# Fixed: Moved css from Blocks constructor to launch()
|
| 85 |
+
with gr.Blocks() as demo:
|
| 86 |
gr.Markdown("# π‘οΈ SecurePass Pro Analyzer")
|
| 87 |
|
|
|
|
| 88 |
visible_state = gr.State(True)
|
| 89 |
+
dark_state = gr.State(False)
|
| 90 |
|
| 91 |
with gr.Row():
|
| 92 |
with gr.Column(scale=4):
|
| 93 |
with gr.Row():
|
| 94 |
+
# Fixed: Changed show_copy_button to copy_to_clipboard
|
| 95 |
pass_input = gr.Textbox(
|
| 96 |
label="Enter Password",
|
| 97 |
type="password",
|
| 98 |
+
copy_to_clipboard=True,
|
| 99 |
scale=9
|
| 100 |
)
|
| 101 |
show_btn = gr.Button("ποΈ", elem_classes="eye-btn", scale=1)
|
|
|
|
| 108 |
checklist_area = gr.HTML(value=render_checklist("")[0])
|
| 109 |
|
| 110 |
with gr.Row():
|
|
|
|
| 111 |
dark_btn = gr.Button("π Dark Mode", variant="secondary")
|
| 112 |
reset_btn = gr.Button("ποΈ Clear", variant="stop")
|
| 113 |
|
|
|
|
| 114 |
pass_input.change(analyze_password, pass_input, [checklist_area, strength_meter, time_output])
|
| 115 |
show_btn.click(toggle_visibility, [visible_state], [pass_input, show_btn, visible_state])
|
| 116 |
|
|
|
|
| 117 |
dark_btn.click(
|
| 118 |
toggle_dark_mode,
|
| 119 |
inputs=[dark_state],
|
|
|
|
| 128 |
)
|
| 129 |
|
| 130 |
if __name__ == "__main__":
|
| 131 |
+
# Fixed: CSS is now passed here
|
| 132 |
+
demo.launch(css=custom_css)
|