Anupam251272
commited on
Commit
•
17e3432
1
Parent(s):
c35ed21
Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,8 @@ import logging
|
|
4 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
from transformers import MarianMTModel, MarianTokenizer
|
7 |
-
from PIL import Image, ImageDraw, ImageFont
|
8 |
-
import textwrap
|
9 |
-
import os
|
10 |
from gtts import gTTS
|
11 |
import tempfile
|
12 |
-
from diffusers import DiffusionPipeline
|
13 |
|
14 |
# Configure logging
|
15 |
logging.basicConfig(level=logging.INFO)
|
@@ -135,19 +131,6 @@ class MultilingualGitaAnalyzer:
|
|
135 |
logger.error(f"Error in semantic search: {e}")
|
136 |
return ["An error occurred during semantic search."]
|
137 |
|
138 |
-
def generate_image(self, text):
|
139 |
-
"""Generate an image using the DiffusionPipeline."""
|
140 |
-
try:
|
141 |
-
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
142 |
-
prompt = f"in the style of CNSTLL, {text}, night time, cinestill 800T"
|
143 |
-
image = pipe(prompt).images[0]
|
144 |
-
img_path = 'generated_image.png'
|
145 |
-
image.save(img_path)
|
146 |
-
return img_path
|
147 |
-
except Exception as e:
|
148 |
-
logger.error(f"Error generating image: {e}")
|
149 |
-
return None
|
150 |
-
|
151 |
def generate_audio(self, text):
|
152 |
"""Generate audio from the given text."""
|
153 |
try:
|
@@ -183,22 +166,16 @@ class MultilingualGitaAnalyzer:
|
|
183 |
explanation = "In simple terms, duty means doing what you are supposed to do. It's like your responsibilities or tasks that you need to complete. In today's world, it could be your job, taking care of your family, or helping others. It's about doing the right thing, even when it's hard."
|
184 |
translated_explanation = self.translate_from_english(explanation, target_language=preferred_language)
|
185 |
|
186 |
-
#
|
187 |
-
|
188 |
-
image_path = self.generate_image(translated_results[0])
|
189 |
-
else:
|
190 |
-
image_path = None
|
191 |
|
192 |
-
# Generate audio for the
|
193 |
-
|
194 |
-
audio_path = self.generate_audio(translated_results[0])
|
195 |
-
else:
|
196 |
-
audio_path = None
|
197 |
|
198 |
-
return
|
199 |
except Exception as e:
|
200 |
logger.error(f"Error processing query: {e}")
|
201 |
-
return "An unexpected error occurred.", None
|
202 |
|
203 |
def daily_quote():
|
204 |
# Placeholder for daily quote logic
|
@@ -229,11 +206,10 @@ class MultilingualGitaAnalyzer:
|
|
229 |
submit_btn = gr.Button("Submit")
|
230 |
|
231 |
with gr.Column():
|
232 |
-
output = gr.Textbox(label="Vedas Wisdom")
|
233 |
-
image_output = gr.Image(label="Relevant Image")
|
234 |
audio_output = gr.Audio(label="Relevant Audio")
|
235 |
|
236 |
-
submit_btn.click(process_query, inputs=[question, preferred_language], outputs=[output,
|
237 |
|
238 |
gr.Markdown("## Daily Quote")
|
239 |
daily_quote_output = gr.Textbox(label="Daily Quote", value=daily_quote())
|
|
|
4 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
from transformers import MarianMTModel, MarianTokenizer
|
|
|
|
|
|
|
7 |
from gtts import gTTS
|
8 |
import tempfile
|
|
|
9 |
|
10 |
# Configure logging
|
11 |
logging.basicConfig(level=logging.INFO)
|
|
|
131 |
logger.error(f"Error in semantic search: {e}")
|
132 |
return ["An error occurred during semantic search."]
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
def generate_audio(self, text):
|
135 |
"""Generate audio from the given text."""
|
136 |
try:
|
|
|
166 |
explanation = "In simple terms, duty means doing what you are supposed to do. It's like your responsibilities or tasks that you need to complete. In today's world, it could be your job, taking care of your family, or helping others. It's about doing the right thing, even when it's hard."
|
167 |
translated_explanation = self.translate_from_english(explanation, target_language=preferred_language)
|
168 |
|
169 |
+
# Combine results into a story format
|
170 |
+
story = "\n\n".join(translated_results) + "\n\n" + translated_explanation
|
|
|
|
|
|
|
171 |
|
172 |
+
# Generate audio for the story
|
173 |
+
audio_path = self.generate_audio(story)
|
|
|
|
|
|
|
174 |
|
175 |
+
return story, audio_path
|
176 |
except Exception as e:
|
177 |
logger.error(f"Error processing query: {e}")
|
178 |
+
return "An unexpected error occurred.", None
|
179 |
|
180 |
def daily_quote():
|
181 |
# Placeholder for daily quote logic
|
|
|
206 |
submit_btn = gr.Button("Submit")
|
207 |
|
208 |
with gr.Column():
|
209 |
+
output = gr.Textbox(label="Vedas Wisdom Story")
|
|
|
210 |
audio_output = gr.Audio(label="Relevant Audio")
|
211 |
|
212 |
+
submit_btn.click(process_query, inputs=[question, preferred_language], outputs=[output, audio_output])
|
213 |
|
214 |
gr.Markdown("## Daily Quote")
|
215 |
daily_quote_output = gr.Textbox(label="Daily Quote", value=daily_quote())
|