Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,10 @@ def load_json(path, default):
|
|
13 |
return json.load(f)
|
14 |
return default
|
15 |
|
|
|
|
|
|
|
|
|
16 |
profile = load_json(PROFILE_FILE, {})
|
17 |
daily = load_json(DAILY_FILE, {})
|
18 |
|
@@ -73,53 +77,54 @@ def recent_logs():
|
|
73 |
logs += f"**{d}**: {daily[d]['log']}\n"
|
74 |
return logs
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
def
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
gr.
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
inputs=[name, city, job, about, today_log],
|
108 |
-
outputs=[admin_status, logs_output]
|
109 |
-
)
|
110 |
-
|
111 |
-
with gr.Tab("π¬ Ask About Sheetal"):
|
112 |
-
user_q = gr.Textbox(label="Type your question here:")
|
113 |
-
ask_btn = gr.Button("Ask")
|
114 |
-
answer_box = gr.Textbox(label="Bot answer", interactive=False, lines=2, max_lines=4)
|
115 |
-
ask_btn.click(
|
116 |
-
fn=chatbot_qa,
|
117 |
-
inputs=user_q,
|
118 |
-
outputs=answer_box
|
119 |
)
|
120 |
-
return demo
|
121 |
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if __name__ == "__main__":
|
125 |
demo.launch()
|
|
|
13 |
return json.load(f)
|
14 |
return default
|
15 |
|
16 |
+
def save_json(path, data):
|
17 |
+
with open(path, "w") as f:
|
18 |
+
json.dump(data, f, indent=2)
|
19 |
+
|
20 |
profile = load_json(PROFILE_FILE, {})
|
21 |
daily = load_json(DAILY_FILE, {})
|
22 |
|
|
|
77 |
logs += f"**{d}**: {daily[d]['log']}\n"
|
78 |
return logs
|
79 |
|
80 |
+
ADMIN_PASSWORD = "YourSecret123" # CHANGE THIS!
|
81 |
+
|
82 |
+
def check_password(password):
|
83 |
+
if password == ADMIN_PASSWORD:
|
84 |
+
return gr.update(visible=True), gr.update(value="", visible=False)
|
85 |
+
else:
|
86 |
+
return gr.update(visible=False), gr.update(value="β Access denied. Try again.", visible=True)
|
87 |
+
|
88 |
+
with gr.Blocks(title="Sheetal's Chatbot") as demo:
|
89 |
+
gr.Markdown("# πΈ Sheetal's Personal Chatbot")
|
90 |
+
gr.Markdown("Ask anything about Sheetal!")
|
91 |
+
|
92 |
+
with gr.Tab("π Admin (Sheetal)"):
|
93 |
+
admin_password = gr.Textbox(label="Enter admin password", type="password", max_lines=1)
|
94 |
+
password_status = gr.Textbox(label="Password status", value="", interactive=False, visible=False)
|
95 |
+
unlock_panel = gr.Button("Unlock Admin Panel")
|
96 |
+
|
97 |
+
with gr.Column(visible=False) as admin_panel:
|
98 |
+
with gr.Row():
|
99 |
+
name = gr.Textbox(label="Name", value=profile.get("name", "Sheetal"), max_lines=1)
|
100 |
+
city = gr.Textbox(label="City", value=profile.get("city", ""), max_lines=1)
|
101 |
+
job = gr.Textbox(label="Profession", value=profile.get("job", ""), max_lines=1)
|
102 |
+
about = gr.Textbox(label="About You", value=profile.get("about", ""), lines=2, max_lines=3)
|
103 |
+
today_log = gr.Textbox(label="What do you want to remember about today?", value=daily.get(str(date.today()), {}).get("log", ""), lines=2, max_lines=3)
|
104 |
+
save_btn = gr.Button("πΎ Save Profile & Today's Log")
|
105 |
+
admin_status = gr.Markdown("")
|
106 |
+
logs_output = gr.Markdown(recent_logs())
|
107 |
+
save_btn.click(
|
108 |
+
fn=save_profile_and_log,
|
109 |
+
inputs=[name, city, job, about, today_log],
|
110 |
+
outputs=[admin_status, logs_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
)
|
|
|
112 |
|
113 |
+
unlock_panel.click(
|
114 |
+
fn=check_password,
|
115 |
+
inputs=[admin_password],
|
116 |
+
outputs=[admin_panel, password_status]
|
117 |
+
)
|
118 |
+
|
119 |
+
with gr.Tab("π¬ Ask About Sheetal"):
|
120 |
+
user_q = gr.Textbox(label="Type your question here:")
|
121 |
+
ask_btn = gr.Button("Ask")
|
122 |
+
answer_box = gr.Textbox(label="Bot answer", interactive=False, lines=2, max_lines=4)
|
123 |
+
ask_btn.click(
|
124 |
+
fn=chatbot_qa,
|
125 |
+
inputs=user_q,
|
126 |
+
outputs=answer_box
|
127 |
+
)
|
128 |
+
|
129 |
if __name__ == "__main__":
|
130 |
demo.launch()
|