Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,9 +37,8 @@ def chatbot_qa(user_q):
|
|
37 |
try:
|
38 |
result = qa_pipeline(question=user_q, context=context)
|
39 |
answer = result["answer"].strip()
|
40 |
-
# If the model cannot answer, it often returns '' or 'empty'
|
41 |
if not answer or answer.lower() in ["empty", ""]:
|
42 |
-
return "Sheetal hasn't shared that yet!"
|
43 |
return answer
|
44 |
except Exception as e:
|
45 |
return f"Error: {e}"
|
@@ -69,7 +68,7 @@ def recent_logs():
|
|
69 |
logs += f"**{d}**: {daily[d]['log']}\n"
|
70 |
return logs
|
71 |
|
72 |
-
ADMIN_PASSWORD = "
|
73 |
|
74 |
def check_password(password):
|
75 |
if password == ADMIN_PASSWORD:
|
@@ -81,50 +80,87 @@ def show_profile():
|
|
81 |
return json.dumps(profile, indent=2), json.dumps(daily, indent=2)
|
82 |
|
83 |
with gr.Blocks(title="Sheetal's Chatbot") as demo:
|
84 |
-
gr.
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
unlock_panel = gr.Button("Unlock Admin Panel")
|
90 |
-
password_status = gr.Textbox(label="Password status", value="", interactive=False, visible=False)
|
91 |
|
92 |
-
with gr.
|
93 |
with gr.Row():
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
)
|
107 |
-
# Debug: show current data
|
108 |
-
show_btn = gr.Button("Show Current Data")
|
109 |
-
profile_out = gr.Textbox(label="Profile JSON")
|
110 |
-
daily_out = gr.Textbox(label="Daily JSON")
|
111 |
-
show_btn.click(fn=show_profile, outputs=[profile_out, daily_out])
|
112 |
-
|
113 |
-
unlock_panel.click(
|
114 |
-
fn=check_password,
|
115 |
-
inputs=[admin_password],
|
116 |
-
outputs=[admin_panel, password_status]
|
117 |
-
)
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
if __name__ == "__main__":
|
130 |
demo.launch()
|
|
|
37 |
try:
|
38 |
result = qa_pipeline(question=user_q, context=context)
|
39 |
answer = result["answer"].strip()
|
|
|
40 |
if not answer or answer.lower() in ["empty", ""]:
|
41 |
+
return "π€·ββοΈ Sheetal hasn't shared that yet!"
|
42 |
return answer
|
43 |
except Exception as e:
|
44 |
return f"Error: {e}"
|
|
|
68 |
logs += f"**{d}**: {daily[d]['log']}\n"
|
69 |
return logs
|
70 |
|
71 |
+
ADMIN_PASSWORD = "123" # CHANGE THIS!
|
72 |
|
73 |
def check_password(password):
|
74 |
if password == ADMIN_PASSWORD:
|
|
|
80 |
return json.dumps(profile, indent=2), json.dumps(daily, indent=2)
|
81 |
|
82 |
with gr.Blocks(title="Sheetal's Chatbot") as demo:
|
83 |
+
with gr.Column():
|
84 |
+
gr.Markdown(
|
85 |
+
"<h1 style='text-align:center; color:#AC3B61;'>πΈ Sheetal's Personal Chatbot πΈ</h1>"
|
86 |
+
"<div style='text-align:center;'>Ask anything about Sheetal!<br>Made with β€οΈ on Hugging Face Spaces.</div>"
|
87 |
+
)
|
|
|
|
|
88 |
|
89 |
+
with gr.Tab("π©βπ» Ask About Sheetal"):
|
90 |
with gr.Row():
|
91 |
+
user_q = gr.Textbox(
|
92 |
+
label="Ask your question here:",
|
93 |
+
placeholder="e.g., Who cooked for Sheetal today?",
|
94 |
+
lines=1,
|
95 |
+
scale=6
|
96 |
+
)
|
97 |
+
ask_btn = gr.Button("π Ask", scale=1)
|
98 |
+
answer_box = gr.Textbox(
|
99 |
+
label="π€ Chatbot Answer",
|
100 |
+
interactive=False,
|
101 |
+
lines=3,
|
102 |
+
max_lines=5,
|
103 |
+
elem_id="answer_box"
|
104 |
+
)
|
105 |
+
gr.Markdown(
|
106 |
+
"<div style='font-size:13px; color:gray;'>"
|
107 |
+
"Tip: The bot only knows what Sheetal has shared in her profile or daily logs.</div>"
|
108 |
+
)
|
109 |
+
ask_btn.click(
|
110 |
+
fn=chatbot_qa,
|
111 |
+
inputs=user_q,
|
112 |
+
outputs=answer_box
|
113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
+
with gr.Tab("π Admin Panel (Sheetal only)"):
|
116 |
+
with gr.Row():
|
117 |
+
admin_password = gr.Textbox(label="Admin Password", type="password", max_lines=1, scale=3)
|
118 |
+
unlock_panel = gr.Button("π Unlock", scale=1)
|
119 |
+
password_status = gr.Textbox(
|
120 |
+
label="",
|
121 |
+
value="",
|
122 |
+
interactive=False,
|
123 |
+
visible=False,
|
124 |
+
scale=4
|
125 |
+
)
|
126 |
+
with gr.Column(visible=False) as admin_panel:
|
127 |
+
gr.Markdown("<h4 style='color:#123C69;'>Update your profile & log for today</h4>")
|
128 |
+
with gr.Row():
|
129 |
+
name = gr.Textbox(label="Name", value=profile.get("name", "Sheetal"))
|
130 |
+
city = gr.Textbox(label="City", value=profile.get("city", ""))
|
131 |
+
with gr.Row():
|
132 |
+
job = gr.Textbox(label="Profession", value=profile.get("job", ""))
|
133 |
+
about = gr.Textbox(label="About You", value=profile.get("about", ""), lines=2, max_lines=3)
|
134 |
+
today_log = gr.Textbox(label="Daily Note", value=daily.get(str(date.today()), {}).get("log", ""), lines=2, max_lines=4)
|
135 |
+
with gr.Row():
|
136 |
+
save_btn = gr.Button("πΎ Save Profile & Today's Log", scale=2)
|
137 |
+
show_btn = gr.Button("π Show Current Data", scale=1)
|
138 |
+
admin_status = gr.Markdown()
|
139 |
+
logs_output = gr.Markdown(f"<b>Recent logs:</b>\n{recent_logs()}")
|
140 |
+
profile_out = gr.Textbox(label="Profile JSON", visible=False)
|
141 |
+
daily_out = gr.Textbox(label="Daily Logs JSON", visible=False)
|
142 |
+
|
143 |
+
save_btn.click(
|
144 |
+
fn=save_profile_and_log,
|
145 |
+
inputs=[name, city, job, about, today_log],
|
146 |
+
outputs=[admin_status, logs_output]
|
147 |
+
)
|
148 |
+
show_btn.click(fn=show_profile, outputs=[profile_out, daily_out])
|
149 |
+
|
150 |
+
unlock_panel.click(
|
151 |
+
fn=check_password,
|
152 |
+
inputs=[admin_password],
|
153 |
+
outputs=[admin_panel, password_status]
|
154 |
+
)
|
155 |
+
with gr.Accordion("π View Raw JSON Data (Debug)", open=False):
|
156 |
+
profile_out = gr.Textbox(label="Profile JSON", interactive=False)
|
157 |
+
daily_out = gr.Textbox(label="Daily Logs JSON", interactive=False)
|
158 |
+
|
159 |
+
gr.Markdown(
|
160 |
+
"<hr><div style='text-align:center; color: #888; font-size: 12px;'>"
|
161 |
+
"Sheetal's Chatbot © 2024 • Powered by Hugging Face + Gradio"
|
162 |
+
"</div>"
|
163 |
+
)
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
demo.launch()
|