sreelekhaputta2 commited on
Commit
df6393c
Β·
verified Β·
1 Parent(s): d762217

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -14,9 +14,10 @@ df = pd.read_csv("bhagavad_gita.csv")
14
  model = SentenceTransformer("all-MiniLM-L6-v2")
15
  verse_embeddings = model.encode(df['meaning_in_english'].tolist(), convert_to_tensor=True)
16
 
17
- # Temp folder for audio files and downloads
18
  TEMP_DIR = tempfile.mkdtemp()
19
 
 
20
  bg_music_path = "krishna_bg_music.mp3"
21
 
22
  def shorten_explanation(text, max_sentences=2):
@@ -61,16 +62,15 @@ def versewise_bot(question, play_music):
61
  explanation = shorten_explanation(verse['meaning_in_english'])
62
  verse_number = verse['verse_number']
63
 
64
- reply = f"""πŸ“– Bhagavad Gita {verse_number}
65
-
66
- πŸ•‰ "[translate:{sanskrit[:60]}...]"
67
-
68
- "{translation}"
69
-
70
- πŸ•Š {explanation}
71
-
72
- 🌼 Stay strong β€” Krishna walks with you."""
73
 
 
74
  music_path = None
75
  if play_music and os.path.exists(bg_music_path):
76
  unique_bgm_path = os.path.join(TEMP_DIR, f"bgm_{uuid.uuid4()}.mp3")
@@ -80,6 +80,7 @@ def versewise_bot(question, play_music):
80
  except Exception as e:
81
  print(f"BGM Error: {e}")
82
 
 
83
  download_file = create_downloadable_text(question, verse_number, sanskrit, translation, explanation)
84
 
85
  return reply, None, music_path, download_file
@@ -89,10 +90,10 @@ def get_quote_of_the_day():
89
  sanskrit = verse['verse_in_sanskrit']
90
  translation = verse['translation_in_english']
91
  verse_number = verse['verse_number']
92
- return f"""<div style="font-size:1.1em;padding:10px 0;">
93
  <b>Quote of the Day (Gita {verse_number}):</b><br>
94
  <i>[translate:{sanskrit[:60]}...]</i><br>
95
- <span style="color:#2d2d2d;">"{translation}"</span></div>"""
96
 
97
  custom_css = """
98
  body, .gradio-container, .gradio-interface, html {
@@ -110,6 +111,15 @@ body, .gradio-container, .gradio-interface, html {
110
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
111
  margin: auto;
112
  }
 
 
 
 
 
 
 
 
 
113
  """
114
 
115
  interface = gr.Interface(
@@ -120,9 +130,9 @@ interface = gr.Interface(
120
  ],
121
  outputs=[
122
  gr.Textbox(label="πŸ§˜β€β™‚ Krishna's Answer"),
123
- gr.Audio(label="πŸ”Š Krishna’s Voice", type="filepath"),
124
  gr.Audio(label="🎢 Background Music", autoplay=True, type="filepath"),
125
- gr.DownloadButton(label="Download Response with Assurance", type="file")
126
  ],
127
  title="πŸ•‰ VerseWise - Divine Wisdom from the Gita",
128
  description="Ask any question, and receive a verse from the Bhagavad Gita with divine guidance.",
 
14
  model = SentenceTransformer("all-MiniLM-L6-v2")
15
  verse_embeddings = model.encode(df['meaning_in_english'].tolist(), convert_to_tensor=True)
16
 
17
+ # Temporary directory for audio and downloads
18
  TEMP_DIR = tempfile.mkdtemp()
19
 
20
+ # Background music file path
21
  bg_music_path = "krishna_bg_music.mp3"
22
 
23
  def shorten_explanation(text, max_sentences=2):
 
62
  explanation = shorten_explanation(verse['meaning_in_english'])
63
  verse_number = verse['verse_number']
64
 
65
+ reply = (
66
+ f"πŸ“– Bhagavad Gita {verse_number}\n\n"
67
+ f"πŸ•‰ \"[translate:{sanskrit[:60]}...]\"\n\n"
68
+ f"\"{translation}\"\n\n"
69
+ f"πŸ•Š {explanation}\n\n"
70
+ "🌼 Stay strong β€” Krishna walks with you."
71
+ )
 
 
72
 
73
+ # Background music handling
74
  music_path = None
75
  if play_music and os.path.exists(bg_music_path):
76
  unique_bgm_path = os.path.join(TEMP_DIR, f"bgm_{uuid.uuid4()}.mp3")
 
80
  except Exception as e:
81
  print(f"BGM Error: {e}")
82
 
83
+ # Create downloadable text file
84
  download_file = create_downloadable_text(question, verse_number, sanskrit, translation, explanation)
85
 
86
  return reply, None, music_path, download_file
 
90
  sanskrit = verse['verse_in_sanskrit']
91
  translation = verse['translation_in_english']
92
  verse_number = verse['verse_number']
93
+ return (f'''<div style="font-size:1.1em;padding:10px 0;">
94
  <b>Quote of the Day (Gita {verse_number}):</b><br>
95
  <i>[translate:{sanskrit[:60]}...]</i><br>
96
+ <span style="color:#2d2d2d;">"{translation}"</span></div>''')
97
 
98
  custom_css = """
99
  body, .gradio-container, .gradio-interface, html {
 
111
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
112
  margin: auto;
113
  }
114
+ @media only screen and (max-width: 768px) {
115
+ .gradio-container {
116
+ width: 95% !important;
117
+ padding: 15px !important;
118
+ }
119
+ }
120
+ input[type="text"], textarea {
121
+ font-size: 16px !important;
122
+ }
123
  """
124
 
125
  interface = gr.Interface(
 
130
  ],
131
  outputs=[
132
  gr.Textbox(label="πŸ§˜β€β™‚ Krishna's Answer"),
133
+ gr.Audio(label="πŸ”Š Krishna’s Voice", type="filepath"), # Always None since TTS removed
134
  gr.Audio(label="🎢 Background Music", autoplay=True, type="filepath"),
135
+ gr.DownloadButton(label="Download Response with Assurance")
136
  ],
137
  title="πŸ•‰ VerseWise - Divine Wisdom from the Gita",
138
  description="Ask any question, and receive a verse from the Bhagavad Gita with divine guidance.",