sreelekhaputta2 commited on
Commit
ce81e14
·
verified ·
1 Parent(s): b8d599a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -0
app.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Step 1: Install Gradio
2
+ !pip install gradio
3
+
4
+ # Step 2: Upload JSON and bg.png files
5
+ from google.colab import files
6
+ uploaded = files.upload() # Upload: gita_techies_18_chapters.json + bg.png
7
+
8
+ import json
9
+ import random
10
+ import gradio as gr
11
+ import base64
12
+
13
+ # Step 3: Load JSON data
14
+ with open("gita_techies_18_chapters.json", "r", encoding="utf-8") as f:
15
+ gita_for_techies = json.load(f)
16
+
17
+ # Step 4: Encode background image as Base64
18
+ with open("bg.png", "rb") as img_file:
19
+ b64_bg_img = base64.b64encode(img_file.read()).decode()
20
+
21
+ # Step 5: Define function to get random Gita entry formatted as HTML
22
+ def get_gita_tech():
23
+ entry = random.choice(gita_for_techies)
24
+ return f"""
25
+ <div class="content">
26
+ <h2>📘 Chapter {entry["chapter_number"]}</h2>
27
+
28
+ <p><b>🌼 Spiritual Meaning (EN):</b><br>{entry["spiritual_meaning_en"]}</p>
29
+ <p><b>🪔 ఆధ్యాత్మిక అర్థం (TE):</b><br>{entry["spiritual_meaning_te"]}</p>
30
+
31
+ <p><b>💻 Tech Meaning (EN):</b><br>{entry["tech_meaning_en"]}</p>
32
+ <p><b>🌾 టెక్ అర్థం (TE):</b><br>{entry["tech_meaning_te"]}</p>
33
+
34
+ <p><b>🧠 Lesson for Techies:</b><br>{entry["lesson_for_techies"]}</p>
35
+ <p><b>⚙️ Tech Stack Analogy:</b><br>{entry["tech_stack_analogy"]}</p>
36
+
37
+ <p><b>🧘 Daily Reminder (EN):</b><br><i>{entry["daily_reminder_en"]}</i></p>
38
+ <p><b>🧘 రోజువారీ స్మరణ (TE):</b><br><i>{entry["daily_reminder_te"]}</i></p>
39
+
40
+ <p><b>🧾 Code Snippet:</b></p>
41
+ <pre><code>{entry["code_snippet"]}</code></pre>
42
+
43
+ <hr style="margin-top: 30px;">
44
+ <p style="text-align:center;font-size:0.9rem;">🪷 Made with 💜 by <b>Sreelekha Putta</b></p>
45
+ </div>
46
+
47
+ <style>
48
+ .content {{
49
+ background: rgba(20, 15, 35, 0.9);
50
+ padding: 25px 20px;
51
+ border-radius: 16px;
52
+ max-width: 800px;
53
+ margin: 0 auto 30px auto;
54
+ box-shadow: 0 0 25px #ab71f7;
55
+ color: #f8e8ff;
56
+ font-family: 'Segoe UI', sans-serif;
57
+ animation: fadeIn 1.5s ease forwards;
58
+ }}
59
+ h2 {{
60
+ color: #d0a8ff;
61
+ font-family: Georgia, serif;
62
+ margin-bottom: 16px;
63
+ }}
64
+ pre {{
65
+ background: #1f2937;
66
+ color: #a5f3fc;
67
+ padding: 12px;
68
+ border-radius: 8px;
69
+ font-size: 0.95rem;
70
+ overflow-x: auto;
71
+ }}
72
+ @keyframes fadeIn {{
73
+ from {{opacity: 0; transform: translateY(20px);}}
74
+ to {{opacity: 1; transform: translateY(0);}}
75
+ }}
76
+ </style>
77
+ """
78
+
79
+ # Step 6: Define CSS with Base64 background image
80
+ css = f"""
81
+ body {{
82
+ margin: 0;
83
+ padding: 20px;
84
+ min-height: 100vh;
85
+ background-image: url("data:image/png;base64,{b64_bg_img}");
86
+ background-size: cover;
87
+ background-position: center;
88
+ background-repeat: no-repeat;
89
+ background-attachment: fixed;
90
+ display: flex;
91
+ flex-direction: column;
92
+ align-items: center;
93
+ justify-content: flex-start;
94
+ font-family: 'Segoe UI', sans-serif;
95
+ }}
96
+ body::before {{
97
+ content: "";
98
+ position: fixed;
99
+ inset: 0;
100
+ background: rgba(0,0,30,0.7);
101
+ z-index: -1;
102
+ }}
103
+ h1 {{
104
+ text-align: center;
105
+ color: #e7c1ff;
106
+ margin: 30px 0 20px 0;
107
+ font-family: Georgia, serif;
108
+ font-weight: 700;
109
+ font-size: 2.8rem;
110
+ text-shadow: 0 0 15px #c084fc;
111
+ }}
112
+ button {{
113
+ background-color: #a855f7;
114
+ border-radius: 12px;
115
+ color: white;
116
+ font-weight: 600;
117
+ font-size: 1.3rem;
118
+ padding: 0.8rem 2.4rem;
119
+ border: none;
120
+ cursor: pointer;
121
+ box-shadow: 0 0 18px #a78bfa88;
122
+ transition: 0.3s ease;
123
+ margin-bottom: 30px;
124
+ }}
125
+ button:hover {{
126
+ background-color: #d8b4fe;
127
+ color: black;
128
+ box-shadow: 0 0 25px #f0d0ff;
129
+ }}
130
+ """
131
+
132
+ # Step 7: Create Gradio app interface
133
+ with gr.Blocks(css=css) as app:
134
+ gr.Markdown("<h1>💻 Bhagavad Gita for Techies 💻</h1>")
135
+ output = gr.HTML()
136
+ btn = gr.Button("🔁 Get Wisdom Tip")
137
+ btn.click(fn=get_gita_tech, outputs=output)
138
+
139
+ app.launch()