parvalijaved commited on
Commit
3916b69
·
verified ·
1 Parent(s): ab07d1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -32
app.py CHANGED
@@ -18,37 +18,35 @@ st.title("Bhagavad Gita")
18
  # Fetch and display chapters and verses
19
  data = fetch_data()
20
 
21
- # Ensure data is correctly structured
22
  if isinstance(data, list):
23
- st.error("JSON data structure is not as expected. Please check the JSON file structure.")
24
-
25
- else:
26
- # Convert keys to integers for easier sorting and selection
27
- data = {int(chapter): details for chapter, details in data.items()}
28
-
29
- # Select Chapter
30
- chapter_id = st.selectbox("Select Chapter", sorted(data.keys()), format_func=lambda x: f"Chapter {x}")
31
-
32
- # Display chapter summary if available
33
- chapter_summary = data[chapter_id].get('chapter_summary', 'No summary available')
34
- st.subheader(f"Chapter {chapter_id}")
35
- st.markdown(f"**Summary:**\n\n{chapter_summary}")
36
-
37
- # Extract verses for the selected chapter
38
- verses = {verse['verse_number']: verse for verse in data[chapter_id]['verses']}
39
- verse_number = st.selectbox("Select Verse", sorted(verses.keys()))
40
-
41
- # Display selected verse
42
- selected_verse = verses[verse_number]
 
 
 
 
 
 
43
  st.markdown(f"**Verse {verse_number}**")
44
- st.markdown(f"**Sanskrit:**\n\n{selected_verse['text']}")
45
- st.markdown(f"**Translation:**\n\n{selected_verse['translation']}")
46
-
47
- # Display all verses in the selected chapter
48
- st.subheader("All Verses in this Chapter")
49
- for verse_number in sorted(verses.keys()):
50
- verse = verses[verse_number]
51
- st.markdown(f"**Verse {verse_number}**")
52
- st.markdown(f"**Sanskrit:** {verse['text']}")
53
- st.markdown(f"**Translation:** {verse['translation']}")
54
- st.markdown("---")
 
18
  # Fetch and display chapters and verses
19
  data = fetch_data()
20
 
21
+ # Check the type of data and parse accordingly
22
  if isinstance(data, list):
23
+ chapters = {int(chapter["chapter_number"]): chapter for chapter in data}
24
+ else: # Assuming data is a dictionary
25
+ chapters = {int(chapter_number): details for chapter_number, details in data.items()}
26
+
27
+ # Select Chapter
28
+ chapter_id = st.selectbox("Select Chapter", sorted(chapters.keys()), format_func=lambda x: f"Chapter {x}")
29
+
30
+ # Display chapter summary if available
31
+ chapter_summary = chapters[chapter_id].get('chapter_summary', 'No summary available')
32
+ st.subheader(f"Chapter {chapter_id}")
33
+ st.markdown(f"**Summary:**\n\n{chapter_summary}")
34
+
35
+ # Extract verses for the selected chapter
36
+ verses = {verse['verse_number']: verse for verse in chapters[chapter_id]['verses']}
37
+ verse_number = st.selectbox("Select Verse", sorted(verses.keys()))
38
+
39
+ # Display selected verse
40
+ selected_verse = verses[verse_number]
41
+ st.markdown(f"**Verse {verse_number}**")
42
+ st.markdown(f"**Sanskrit:**\n\n{selected_verse['text']}")
43
+ st.markdown(f"**Translation:**\n\n{selected_verse['translation']}")
44
+
45
+ # Display all verses in the selected chapter
46
+ st.subheader("All Verses in this Chapter")
47
+ for verse_number in sorted(verses.keys()):
48
+ verse = verses[verse_number]
49
  st.markdown(f"**Verse {verse_number}**")
50
+ st.markdown(f"**Sanskrit:** {verse['text']}")
51
+ st.markdown(f"**Translation:** {verse['translation']}")
52
+ st.markdown("---")