Spaces:
Sleeping
Sleeping
parvalijaved
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,49 @@
|
|
|
|
1 |
import requests
|
|
|
2 |
|
3 |
# URL to the JSON file
|
4 |
JSON_URL = "https://cdn.statically.io/gh/gita/gita/main/data/verse.json"
|
5 |
|
6 |
# Fetch the JSON data
|
|
|
7 |
def fetch_data():
|
8 |
response = requests.get(JSON_URL)
|
9 |
response.raise_for_status()
|
10 |
return response.json()
|
11 |
|
12 |
-
#
|
|
|
|
|
|
|
13 |
data = fetch_data()
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
import requests
|
3 |
+
import json
|
4 |
|
5 |
# URL to the JSON file
|
6 |
JSON_URL = "https://cdn.statically.io/gh/gita/gita/main/data/verse.json"
|
7 |
|
8 |
# Fetch the JSON data
|
9 |
+
@st.cache_data
|
10 |
def fetch_data():
|
11 |
response = requests.get(JSON_URL)
|
12 |
response.raise_for_status()
|
13 |
return response.json()
|
14 |
|
15 |
+
# Streamlit app
|
16 |
+
st.title("Bhagavad Gita")
|
17 |
+
|
18 |
+
# Fetch and display chapters and verses
|
19 |
data = fetch_data()
|
20 |
+
|
21 |
+
# Convert keys to integers for easier sorting and selection
|
22 |
+
data = {int(chapter): details for chapter, details in data.items()}
|
23 |
+
|
24 |
+
# Select Chapter
|
25 |
+
chapter_id = st.selectbox("Select Chapter", sorted(data.keys()), format_func=lambda x: f"Chapter {x}")
|
26 |
+
|
27 |
+
# Display chapter summary if available
|
28 |
+
chapter_summary = data[chapter_id].get('chapter_summary', 'No summary available')
|
29 |
+
st.subheader(f"Chapter {chapter_id}")
|
30 |
+
st.markdown(f"**Summary:**\n\n{chapter_summary}")
|
31 |
+
|
32 |
+
# Extract verses for the selected chapter
|
33 |
+
verses = {verse['verse_number']: verse for verse in data[chapter_id]['verses']}
|
34 |
+
verse_number = st.selectbox("Select Verse", sorted(verses.keys()))
|
35 |
+
|
36 |
+
# Display selected verse
|
37 |
+
selected_verse = verses[verse_number]
|
38 |
+
st.markdown(f"**Verse {verse_number}**")
|
39 |
+
st.markdown(f"**Sanskrit:**\n\n{selected_verse['text']}")
|
40 |
+
st.markdown(f"**Translation:**\n\n{selected_verse['translation']}")
|
41 |
+
|
42 |
+
# Display all verses in the selected chapter
|
43 |
+
st.subheader("All Verses in this Chapter")
|
44 |
+
for verse_number in sorted(verses.keys()):
|
45 |
+
verse = verses[verse_number]
|
46 |
+
st.markdown(f"**Verse {verse_number}**")
|
47 |
+
st.markdown(f"**Sanskrit:** {verse['text']}")
|
48 |
+
st.markdown(f"**Translation:** {verse['translation']}")
|
49 |
+
st.markdown("---")
|