import json
import random
import gradio as gr
import base64
# Load JSON dataset
with open("gita_techies_18_chapters.json", "r", encoding="utf-8") as f:
gita_for_techies = json.load(f)
# Encode background image
with open("bg.png", "rb") as img_file:
b64_bg_img = base64.b64encode(img_file.read()).decode()
# Function to return one random entry
def get_gita_tech():
entry = random.choice(gita_for_techies)
return f"""
📘 Chapter {entry["chapter_number"]}
🌼 Spiritual Meaning (EN):
{entry["spiritual_meaning_en"]}
🪔 ఆధ్యాత్మిక అర్థం (TE):
{entry["spiritual_meaning_te"]}
💻 Tech Meaning (EN):
{entry["tech_meaning_en"]}
🌾 టెక్ అర్థం (TE):
{entry["tech_meaning_te"]}
🧠 Lesson for Techies:
{entry["lesson_for_techies"]}
⚙️ Tech Stack Analogy:
{entry["tech_stack_analogy"]}
🧘 Daily Reminder (EN):
{entry["daily_reminder_en"]}
🧘 రోజువారీ స్మరణ (TE):
{entry["daily_reminder_te"]}
🧾 Code Snippet:
{entry["code_snippet"]}
🌸 Made with 💜 by Sreelekha Putta
"""
# CSS with background
css = f"""
body {{
margin: 0;
padding: 0;
min-height: 100vh;
background-image: url("data:image/png;base64,{b64_bg_img}");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: 'Segoe UI', sans-serif;
}}
body::before {{
content: "";
position: fixed;
inset: 0;
background: rgba(0,0,30,0.7);
z-index: -1;
}}
h1 {{
text-align: center;
color: #e7c1ff;
font-size: 2.8rem;
font-weight: 700;
margin: 30px 0 20px 0;
text-shadow: 0 0 15px #c084fc;
}}
button {{
background-color: #a855f7;
border-radius: 12px;
color: white;
font-weight: 600;
font-size: 1.3rem;
padding: 0.8rem 2.4rem;
border: none;
cursor: pointer;
margin-bottom: 30px;
box-shadow: 0 0 18px #a78bfa88;
}}
button:hover {{
background-color: #d8b4fe;
color: black;
box-shadow: 0 0 25px #f0d0ff;
}}
"""
# Gradio interface
with gr.Blocks(css=css) as app:
gr.Markdown("