vikramvasudevan commited on
Commit
914dd1a
·
verified ·
1 Parent(s): 9320e6c

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +38 -2
  2. modules/nodes/init.py +1 -11
app.py CHANGED
@@ -84,6 +84,10 @@ with gr.Blocks(
84
  theme=gr.themes.Citrus(),
85
  title="Sanatan-AI",
86
  css="""
 
 
 
 
87
  table {
88
  border-collapse: collapse;
89
  width: 90%;
@@ -191,6 +195,19 @@ with gr.Blocks(
191
  preferred_language = gr.Dropdown(
192
  choices=get_all_languages(), value="English", label="Preferred Language"
193
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  chatbot = gr.Chatbot(
195
  elem_id="chatbot",
196
  avatar_images=("assets/avatar_user.png", "assets/adiyen_bot.png"),
@@ -199,16 +216,35 @@ with gr.Blocks(
199
  show_copy_button=True,
200
  show_copy_all_button=True,
201
  type="messages",
202
- height=700,
203
  render_markdown=True,
 
204
  )
205
 
 
 
 
206
  chatInterface = gr.ChatInterface(
207
  title="Sanatan-AI",
208
  fn=chat_wrapper,
209
  additional_inputs=[thread_id, debug_checkbox, preferred_language],
 
210
  chatbot=chatbot,
211
  textbox=message_textbox,
 
212
  )
213
 
214
- # app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  theme=gr.themes.Citrus(),
85
  title="Sanatan-AI",
86
  css="""
87
+ /* hide the additional inputs row under the textbox */
88
+ .gr-chat-interface .gr-form {
89
+ display: none !important;
90
+ }
91
  table {
92
  border-collapse: collapse;
93
  width: 90%;
 
195
  preferred_language = gr.Dropdown(
196
  choices=get_all_languages(), value="English", label="Preferred Language"
197
  )
198
+ followup_shortcuts = {
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"),
 
216
  show_copy_button=True,
217
  show_copy_all_button=True,
218
  type="messages",
219
+ height=600,
220
  render_markdown=True,
221
+ placeholder="Search the scriptures ...",
222
  )
223
 
224
+ additional_inputs = gr.Accordion(
225
+ label="Additional Inputs", open=False, visible=False
226
+ )
227
  chatInterface = gr.ChatInterface(
228
  title="Sanatan-AI",
229
  fn=chat_wrapper,
230
  additional_inputs=[thread_id, debug_checkbox, preferred_language],
231
+ additional_inputs_accordion=additional_inputs,
232
  chatbot=chatbot,
233
  textbox=message_textbox,
234
+ type="messages",
235
  )
236
 
237
+ with gr.Row(visible=False) as followup_examples:
238
+ gr.Examples(
239
+ label="Follow-ups",
240
+ example_labels=[key for key in followup_shortcuts.keys()],
241
+ examples=[value for value in followup_shortcuts.values()],
242
+ inputs=[message_textbox],
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)
modules/nodes/init.py CHANGED
@@ -83,17 +83,6 @@ In the header at the end for the field `verse_or_page`, show the `verse` or `pag
83
  - Give a **short, natural summary/meaning** in {state['language']}.
84
  - Keep it concise and error-free. Do not give word-by-word meanings here even if available.
85
 
86
- ### 🔮 Next Steps
87
- End with a short list of follow-up prompts:
88
- - "Do you want detailed notes or purport?"
89
- - "Do you want word-by-word meaning in English?"
90
- - "Do you want word-by-word meaning in {state['language']}?"
91
- - "Seeing garbled characters in the native verses? Ask me to sanitize it."
92
- - **Also think of two additional, natural follow-up questions based on this verse’s content.**
93
- - At least one of these must suggest a **cross-reference with another scripture**.
94
- (Example: if the verse is from Divya Prabandham praising Krishna, suggest checking how the Bhagavatam or Vishnu Sahasranama describes the same quality.)
95
- - The second can be any natural next curiosity the user might have — e.g., related verses, next pasuram, or thematic elaboration.
96
-
97
  ---
98
 
99
  ### 📌 Optional Sections (only if explicitly asked OR available in context)
@@ -114,6 +103,7 @@ End with a short list of follow-up prompts:
114
 
115
  ⚠️ Rules:
116
  - For a follow-up question, if the user does not specify a context in the question, assume it is for the verse returned by the previous response.For e.g. "word by word meaning" implies that the user wants to know "the word by word meaning for the above pasuram".
 
117
  - Do not duplicate content across sections.
118
  - Do not invent verses, meanings, or purports.
119
  - If no context found → reply in {state['language']}:
 
83
  - Give a **short, natural summary/meaning** in {state['language']}.
84
  - Keep it concise and error-free. Do not give word-by-word meanings here even if available.
85
 
 
 
 
 
 
 
 
 
 
 
 
86
  ---
87
 
88
  ### 📌 Optional Sections (only if explicitly asked OR available in context)
 
103
 
104
  ⚠️ Rules:
105
  - For a follow-up question, if the user does not specify a context in the question, assume it is for the verse returned by the previous response.For e.g. "word by word meaning" implies that the user wants to know "the word by word meaning for the above pasuram".
106
+ - For questions like this 'From the same prabandham as above, show the first pasuram from the previous decade', assume the user is talking about the same prabandham_code and ensure you pass that in the metadata filter.
107
  - Do not duplicate content across sections.
108
  - Do not invent verses, meanings, or purports.
109
  - If no context found → reply in {state['language']}: