shee2205 commited on
Commit
890d3f9
Β·
verified Β·
1 Parent(s): aa99297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -43
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 = "YourSecret123" # CHANGE THIS!
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.Markdown("# 🌸 Sheetal's Personal Chatbot")
85
- gr.Markdown("Ask anything about Sheetal!")
86
-
87
- with gr.Tab("πŸ“ Admin (Sheetal)"):
88
- admin_password = gr.Textbox(label="Enter admin password", type="password", max_lines=1)
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.Column(visible=False) as admin_panel:
93
  with gr.Row():
94
- name = gr.Textbox(label="Name", value=profile.get("name", "Sheetal"), max_lines=1)
95
- city = gr.Textbox(label="City", value=profile.get("city", ""), max_lines=1)
96
- job = gr.Textbox(label="Profession", value=profile.get("job", ""), max_lines=1)
97
- about = gr.Textbox(label="About You", value=profile.get("about", ""), lines=2, max_lines=3)
98
- 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)
99
- save_btn = gr.Button("πŸ’Ύ Save Profile & Today's Log")
100
- admin_status = gr.Markdown("")
101
- logs_output = gr.Markdown(recent_logs())
102
- save_btn.click(
103
- fn=save_profile_and_log,
104
- inputs=[name, city, job, about, today_log],
105
- outputs=[admin_status, logs_output]
 
 
 
 
 
 
 
 
 
 
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
- 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()
 
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 &copy; 2024 &bull; Powered by Hugging Face + Gradio"
162
+ "</div>"
163
+ )
164
 
165
  if __name__ == "__main__":
166
  demo.launch()