Spaces:
Sleeping
Sleeping
parvalijaved
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# API details
|
5 |
+
API_BASE_URL = "https://bhagavad-gita3.p.rapidapi.com/v2/chapters/"
|
6 |
+
HEADERS = {
|
7 |
+
"X-RapidAPI-Host": "bhagavad-gita3.p.rapidapi.com",
|
8 |
+
"X-RapidAPI-Key": "b69e69cfc9mshe7fec87876dcf14p113691jsn50092eeb2ef8" # Replace with your RapidAPI key
|
9 |
+
}
|
10 |
+
|
11 |
+
# Fetch chapters
|
12 |
+
@st.cache_data
|
13 |
+
def fetch_chapters():
|
14 |
+
response = requests.get(API_BASE_URL, headers=HEADERS)
|
15 |
+
response.raise_for_status()
|
16 |
+
return response.json()
|
17 |
+
|
18 |
+
# Fetch chapter details including summary
|
19 |
+
@st.cache_data
|
20 |
+
def fetch_chapter_details(chapter_id):
|
21 |
+
chapter_url = f"{API_BASE_URL}{chapter_id}"
|
22 |
+
response = requests.get(chapter_url, headers=HEADERS)
|
23 |
+
response.raise_for_status()
|
24 |
+
return response.json()
|
25 |
+
|
26 |
+
# Fetch verses of a specific chapter
|
27 |
+
@st.cache_data
|
28 |
+
def fetch_verses(chapter_id):
|
29 |
+
verses_url = f"{API_BASE_URL}{chapter_id}/verses"
|
30 |
+
response = requests.get(verses_url, headers=HEADERS)
|
31 |
+
response.raise_for_status()
|
32 |
+
return response.json()
|
33 |
+
|
34 |
+
# Fetch a specific verse's details
|
35 |
+
@st.cache_data
|
36 |
+
def fetch_verse_details(chapter_id, verse_id):
|
37 |
+
verse_url = f"{API_BASE_URL}{chapter_id}/verses/{verse_id}/"
|
38 |
+
response = requests.get(verse_url, headers=HEADERS)
|
39 |
+
response.raise_for_status()
|
40 |
+
return response.json()
|
41 |
+
|
42 |
+
# Streamlit app
|
43 |
+
st.title("Bhagavad Gita")
|
44 |
+
|
45 |
+
# Fetch and display chapters
|
46 |
+
chapters = fetch_chapters()
|
47 |
+
chapter_list = {chapter['chapter_number']: chapter['name'] for chapter in chapters}
|
48 |
+
|
49 |
+
chapter_id = st.selectbox("Select Chapter", list(chapter_list.keys()), format_func=lambda x: f"Chapter {x}: {chapter_list[x]}")
|
50 |
+
|
51 |
+
# Fetch and display chapter details
|
52 |
+
chapter_details = fetch_chapter_details(chapter_id)
|
53 |
+
chapter_summary = chapter_details['summary']
|
54 |
+
|
55 |
+
st.subheader(f"Chapter {chapter_id}: {chapter_list[chapter_id]}")
|
56 |
+
st.markdown(f"**Summary:**\n\n{chapter_summary}")
|
57 |
+
|
58 |
+
# Fetch and display verses
|
59 |
+
verses = fetch_verses(chapter_id)
|
60 |
+
|
61 |
+
verse_number = st.selectbox("Select Verse", [verse['verse_number'] for verse in verses])
|
62 |
+
selected_verse = fetch_verse_details(chapter_id, verse_number)
|
63 |
+
|
64 |
+
st.markdown(f"**Sanskrit:**\n\n{selected_verse['text']}")
|
65 |
+
st.markdown(f"**Translation:**\n\n{selected_verse['translation']}")
|
66 |
+
|
67 |
+
# Display all verses in the selected chapter
|
68 |
+
st.subheader("All Verses in this Chapter")
|
69 |
+
for verse in verses:
|
70 |
+
verse_details = fetch_verse_details(chapter_id, verse['verse_number'])
|
71 |
+
st.markdown(f"**Verse {verse['verse_number']}**")
|
72 |
+
st.markdown(f"**Sanskrit:** {verse_details['text']}")
|
73 |
+
st.markdown(f"**Translation:** {verse_details['translation']}")
|
74 |
+
st.markdown("---")
|