Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -195,19 +195,24 @@ with gr.Blocks(
|
|
| 195 |
preferred_language = gr.Dropdown(
|
| 196 |
choices=get_all_languages(), value="English", label="Preferred Language"
|
| 197 |
)
|
| 198 |
-
|
|
|
|
| 199 |
"⬅️ Prev verse": "show me the previous verse",
|
| 200 |
"➡️ Next verse": "show me the next verse",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
"🧹 Sanitize": "sanitize the native verses",
|
| 202 |
"📜 Explain": "provide explanatory notes if available for the above verses",
|
| 203 |
"📜 Detailed Meaning": "provide word by word meaning if available for the above verses",
|
| 204 |
"🏛️ Another divya desam (same āzhwār)": "show pasuram from another divya desam by the same azhwar",
|
| 205 |
"👤 Another āzhwār (same divya desam)": "show pasuram from the same divya desam by another azhwar",
|
| 206 |
-
"⬅️ Prev Chapter": "From the same prabandham as above, show the first pasuram from the previous chapter of the same decade",
|
| 207 |
-
"➡️ Next Chapter": "From the same prabandham as above, show the first pasuram from the next chapter of the same decade",
|
| 208 |
-
"⬅️ Prev Decade": "From the same prabandham as above, show the first pasuram from the previous decade",
|
| 209 |
-
"➡️ Next Decade": "From the same prabandham as above, show the first pasuram from the next decade",
|
| 210 |
}
|
|
|
|
| 211 |
chatbot = gr.Chatbot(
|
| 212 |
elem_id="chatbot",
|
| 213 |
avatar_images=("assets/avatar_user.png", "assets/adiyen_bot.png"),
|
|
@@ -234,17 +239,48 @@ with gr.Blocks(
|
|
| 234 |
type="messages",
|
| 235 |
)
|
| 236 |
|
| 237 |
-
with gr.
|
| 238 |
-
gr.
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
# Function to toggle visibility once chat has started
|
| 246 |
def toggle_examples(history):
|
| 247 |
return gr.update(visible=len(history) > 0)
|
| 248 |
|
|
|
|
|
|
|
|
|
|
| 249 |
# Whenever chatbot updates → toggle examples row
|
| 250 |
-
chatbot.change(toggle_examples, chatbot, followup_examples)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
preferred_language = gr.Dropdown(
|
| 196 |
choices=get_all_languages(), value="English", label="Preferred Language"
|
| 197 |
)
|
| 198 |
+
|
| 199 |
+
navigation_followup_shortcuts = {
|
| 200 |
"⬅️ Prev verse": "show me the previous verse",
|
| 201 |
"➡️ Next verse": "show me the next verse",
|
| 202 |
+
"⬅️ Prev Chapter": "From the same prabandham as above, show the first pasuram from the previous chapter of the same decade",
|
| 203 |
+
"➡️ Next Chapter": "From the same prabandham as above, show the first pasuram from the next chapter of the same decade",
|
| 204 |
+
"⬅️ Prev Decade": "From the same prabandham as above, show the first pasuram from the previous decade",
|
| 205 |
+
"➡️ Next Decade": "From the same prabandham as above, show the first pasuram from the next decade",
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
further_questions_followup_shortcuts = {
|
| 209 |
"🧹 Sanitize": "sanitize the native verses",
|
| 210 |
"📜 Explain": "provide explanatory notes if available for the above verses",
|
| 211 |
"📜 Detailed Meaning": "provide word by word meaning if available for the above verses",
|
| 212 |
"🏛️ Another divya desam (same āzhwār)": "show pasuram from another divya desam by the same azhwar",
|
| 213 |
"👤 Another āzhwār (same divya desam)": "show pasuram from the same divya desam by another azhwar",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
}
|
| 215 |
+
|
| 216 |
chatbot = gr.Chatbot(
|
| 217 |
elem_id="chatbot",
|
| 218 |
avatar_images=("assets/avatar_user.png", "assets/adiyen_bot.png"),
|
|
|
|
| 239 |
type="messages",
|
| 240 |
)
|
| 241 |
|
| 242 |
+
with gr.Column(visible=False) as followup_examples:
|
| 243 |
+
with gr.Row():
|
| 244 |
+
gr.Examples(
|
| 245 |
+
label="Quick Navigation Follow-ups",
|
| 246 |
+
example_labels=[key for key in navigation_followup_shortcuts.keys()],
|
| 247 |
+
examples=[value for value in navigation_followup_shortcuts.values()],
|
| 248 |
+
inputs=[message_textbox],
|
| 249 |
+
examples_per_page=len(
|
| 250 |
+
navigation_followup_shortcuts
|
| 251 |
+
), ## Show all examples in the same page.
|
| 252 |
+
)
|
| 253 |
+
with gr.Row():
|
| 254 |
+
gr.Examples(
|
| 255 |
+
label="Further Questions Follow-ups",
|
| 256 |
+
example_labels=[
|
| 257 |
+
key for key in further_questions_followup_shortcuts.keys()
|
| 258 |
+
],
|
| 259 |
+
examples=[
|
| 260 |
+
value for value in further_questions_followup_shortcuts.values()
|
| 261 |
+
],
|
| 262 |
+
inputs=[message_textbox],
|
| 263 |
+
examples_per_page=len(
|
| 264 |
+
further_questions_followup_shortcuts
|
| 265 |
+
), ## Show all examples in the same page.
|
| 266 |
+
)
|
| 267 |
|
| 268 |
# Function to toggle visibility once chat has started
|
| 269 |
def toggle_examples(history):
|
| 270 |
return gr.update(visible=len(history) > 0)
|
| 271 |
|
| 272 |
+
def hide_examples_while_processing(is_processing: bool):
|
| 273 |
+
return gr.update(visible=not is_processing)
|
| 274 |
+
|
| 275 |
# Whenever chatbot updates → toggle examples row
|
| 276 |
+
# chatbot.change(toggle_examples, chatbot, followup_examples)
|
| 277 |
+
message_textbox.submit(
|
| 278 |
+
hide_examples_while_processing,
|
| 279 |
+
inputs=[gr.State(True)],
|
| 280 |
+
outputs=[followup_examples],
|
| 281 |
+
)
|
| 282 |
+
chatbot.change(
|
| 283 |
+
hide_examples_while_processing,
|
| 284 |
+
inputs=[gr.State(False)],
|
| 285 |
+
outputs=[followup_examples],
|
| 286 |
+
)
|