cryogenic22 commited on
Commit
ca54386
·
verified ·
1 Parent(s): 3d7449a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -62,7 +62,6 @@ class SpiritualThemes:
62
  "meditation guidance"
63
  ]
64
 
65
-
66
  class ContentGenerator:
67
  def __init__(self, openai_api_key, replicate_api_key):
68
  self.llm = OpenAI(api_key=openai_api_key, temperature=0.7)
@@ -142,17 +141,19 @@ class ContentGenerator:
142
  3. Keep length appropriate for Instagram
143
  4. Include cultural context if relevant
144
 
145
- Return in JSON format with keys:
146
- - quote: the spiritual quote text
147
- - author: name of the source
148
- - tradition: specific tradition or philosophy
149
- - theme: primary theme of the quote""",
150
- expected_output="""A JSON object containing the quote details:
 
 
151
  {
152
  "quote": "The quote text",
153
  "author": "Author name",
154
  "tradition": "Spiritual tradition",
155
- "theme": "Primary theme"
156
  }""",
157
  agent=quote_curator
158
  )
@@ -174,8 +175,14 @@ class ContentGenerator:
174
  def _parse_quote_result(self, result):
175
  """Parse the generated quote result"""
176
  try:
 
 
 
 
 
177
  if isinstance(result, str):
178
  result = json.loads(result)
 
179
  return {
180
  "text": result.get('quote', ''),
181
  "author": result.get('author', ''),
@@ -185,7 +192,7 @@ class ContentGenerator:
185
  }
186
  except Exception as e:
187
  log_message(f"❌ Error parsing quote result: {str(e)}", "error")
188
- raise
189
 
190
  def generate_image(self, quote, tradition, theme):
191
  """Generate an image using OpenAI DALL-E with enhanced prompts"""
@@ -230,7 +237,7 @@ class ContentGenerator:
230
  raise
231
 
232
  def generate_audio(self, tradition, theme):
233
- """Generate background music using MusicGen with enhanced variety"""
234
  try:
235
  log_message("🎵 Starting audio generation")
236
 
@@ -259,11 +266,11 @@ class ContentGenerator:
259
  prompt = tradition_prompts.get(theme, tradition_prompts["default"])
260
 
261
  output = self.replicate_client.run(
262
- "meta/musicgen:7be0f12c54a8d0d0d720305c1e6ea10c48d5f0a3afce48478341a0fe682a8787",
263
  input={
 
264
  "prompt": prompt,
265
- "duration": 30,
266
- "model_version": "melody",
267
  "output_format": "mp3"
268
  }
269
  )
@@ -320,7 +327,7 @@ def generate_hashtags(tradition, theme):
320
  }
321
 
322
  custom_tags = tradition_tags.get(tradition, []) + theme_tags.get(theme, [])
323
- return list(set(base_tags + custom_tags))[:15] # Instagram allows max 30 tags, we'll use 15
324
 
325
  def main():
326
  st.set_page_config(
 
62
  "meditation guidance"
63
  ]
64
 
 
65
  class ContentGenerator:
66
  def __init__(self, openai_api_key, replicate_api_key):
67
  self.llm = OpenAI(api_key=openai_api_key, temperature=0.7)
 
141
  3. Keep length appropriate for Instagram
142
  4. Include cultural context if relevant
143
 
144
+ You must respond with a valid JSON object using this exact format:
145
+ {{
146
+ "quote": "The actual quote text",
147
+ "author": "The author's name",
148
+ "tradition": "The spiritual tradition",
149
+ "theme": "The main theme"
150
+ }}""",
151
+ expected_output="""A JSON object containing:
152
  {
153
  "quote": "The quote text",
154
  "author": "Author name",
155
  "tradition": "Spiritual tradition",
156
+ "theme": "Main theme"
157
  }""",
158
  agent=quote_curator
159
  )
 
175
  def _parse_quote_result(self, result):
176
  """Parse the generated quote result"""
177
  try:
178
+ log_message(f"Parsing result: {result}")
179
+ # CrewAI returns object, let's convert it to string first
180
+ if hasattr(result, 'raw_output'):
181
+ result = result.raw_output
182
+
183
  if isinstance(result, str):
184
  result = json.loads(result)
185
+
186
  return {
187
  "text": result.get('quote', ''),
188
  "author": result.get('author', ''),
 
192
  }
193
  except Exception as e:
194
  log_message(f"❌ Error parsing quote result: {str(e)}", "error")
195
+ return self._get_fallback_quote()
196
 
197
  def generate_image(self, quote, tradition, theme):
198
  """Generate an image using OpenAI DALL-E with enhanced prompts"""
 
237
  raise
238
 
239
  def generate_audio(self, tradition, theme):
240
+ """Generate background music using MusicGen"""
241
  try:
242
  log_message("🎵 Starting audio generation")
243
 
 
266
  prompt = tradition_prompts.get(theme, tradition_prompts["default"])
267
 
268
  output = self.replicate_client.run(
269
+ "facebookresearch/musicgen:main", # Updated model version
270
  input={
271
+ "model_version": "large",
272
  "prompt": prompt,
273
+ "duration": 8,
 
274
  "output_format": "mp3"
275
  }
276
  )
 
327
  }
328
 
329
  custom_tags = tradition_tags.get(tradition, []) + theme_tags.get(theme, [])
330
+ return list(set(base_tags + custom_tags))[:15]
331
 
332
  def main():
333
  st.set_page_config(