Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,7 +126,7 @@ class ContentGenerator:
|
|
| 126 |
backstory="""You are a wise curator of spiritual wisdom with extensive knowledge
|
| 127 |
of both ancient traditions and modern spiritual thought. You understand the nuances
|
| 128 |
of different spiritual and philosophical traditions, and can communicate their wisdom
|
| 129 |
-
in an engaging, social media-friendly way.""",
|
| 130 |
llm=self.llm,
|
| 131 |
verbose=True
|
| 132 |
)
|
|
@@ -141,14 +141,14 @@ class ContentGenerator:
|
|
| 141 |
3. Keep length appropriate for Instagram
|
| 142 |
4. Include cultural context if relevant
|
| 143 |
|
| 144 |
-
|
| 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="""
|
| 152 |
{
|
| 153 |
"quote": "The quote text",
|
| 154 |
"author": "Author name",
|
|
@@ -175,23 +175,36 @@ class ContentGenerator:
|
|
| 175 |
def _parse_quote_result(self, result):
|
| 176 |
"""Parse the generated quote result"""
|
| 177 |
try:
|
| 178 |
-
log_message(f"
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
if isinstance(result, str):
|
| 184 |
-
result = json.loads(result)
|
| 185 |
-
|
| 186 |
return {
|
| 187 |
-
"text":
|
| 188 |
-
"author":
|
| 189 |
-
"tradition":
|
| 190 |
-
"theme":
|
| 191 |
"generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 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):
|
|
@@ -243,22 +256,22 @@ class ContentGenerator:
|
|
| 243 |
|
| 244 |
music_prompts = {
|
| 245 |
"Buddhism": {
|
| 246 |
-
"Inner Peace": "Tibetan singing bowls
|
| 247 |
-
"Mindfulness": "Zen flute with soft water sounds, mindful atmosphere",
|
| 248 |
-
"default": "Meditation bells with nature sounds"
|
| 249 |
},
|
| 250 |
"Hinduism": {
|
| 251 |
-
"Devotion": "Indian flute with
|
| 252 |
-
"Wisdom": "Gentle sitar with peaceful drone",
|
| 253 |
-
"default": "Sanskrit chants with soft instrumentation"
|
| 254 |
},
|
| 255 |
"Modern Spirituality": {
|
| 256 |
-
"Awareness": "Ambient synthesizer with crystal bowls",
|
| 257 |
-
"Growth": "Uplifting piano with gentle pads",
|
| 258 |
-
"default": "Modern meditation music with nature sounds"
|
| 259 |
},
|
| 260 |
"default": {
|
| 261 |
-
"default": "Peaceful ambient music with gentle bells"
|
| 262 |
}
|
| 263 |
}
|
| 264 |
|
|
@@ -266,12 +279,13 @@ class ContentGenerator:
|
|
| 266 |
prompt = tradition_prompts.get(theme, tradition_prompts["default"])
|
| 267 |
|
| 268 |
output = self.replicate_client.run(
|
| 269 |
-
"
|
| 270 |
input={
|
| 271 |
-
"model_version": "large",
|
| 272 |
"prompt": prompt,
|
| 273 |
-
"
|
| 274 |
-
"output_format": "mp3"
|
|
|
|
|
|
|
| 275 |
}
|
| 276 |
)
|
| 277 |
|
|
|
|
| 126 |
backstory="""You are a wise curator of spiritual wisdom with extensive knowledge
|
| 127 |
of both ancient traditions and modern spiritual thought. You understand the nuances
|
| 128 |
of different spiritual and philosophical traditions, and can communicate their wisdom
|
| 129 |
+
in an engaging, social media-friendly way. Always return valid JSON.""",
|
| 130 |
llm=self.llm,
|
| 131 |
verbose=True
|
| 132 |
)
|
|
|
|
| 141 |
3. Keep length appropriate for Instagram
|
| 142 |
4. Include cultural context if relevant
|
| 143 |
|
| 144 |
+
Return ONLY a JSON object in this exact format, with no additional text:
|
| 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="""Plain JSON object with no markdown formatting:
|
| 152 |
{
|
| 153 |
"quote": "The quote text",
|
| 154 |
"author": "Author name",
|
|
|
|
| 175 |
def _parse_quote_result(self, result):
|
| 176 |
"""Parse the generated quote result"""
|
| 177 |
try:
|
| 178 |
+
log_message(f"Raw result type: {type(result)}")
|
| 179 |
+
log_message(f"Raw result content: {result}")
|
| 180 |
+
|
| 181 |
+
# Handle CrewOutput object
|
| 182 |
+
if hasattr(result, 'result'):
|
| 183 |
+
result_str = str(result.result)
|
| 184 |
+
else:
|
| 185 |
+
result_str = str(result)
|
| 186 |
+
|
| 187 |
+
log_message(f"Processing result string: {result_str}")
|
| 188 |
+
|
| 189 |
+
# Clean the string and extract JSON
|
| 190 |
+
result_str = result_str.strip()
|
| 191 |
+
if result_str.startswith("```json"):
|
| 192 |
+
result_str = result_str[7:-3] # Remove ```json and ``` markers
|
| 193 |
+
|
| 194 |
+
# Parse the JSON
|
| 195 |
+
parsed_json = json.loads(result_str)
|
| 196 |
+
log_message(f"Parsed JSON: {parsed_json}")
|
| 197 |
|
|
|
|
|
|
|
|
|
|
| 198 |
return {
|
| 199 |
+
"text": parsed_json.get('quote', ''),
|
| 200 |
+
"author": parsed_json.get('author', ''),
|
| 201 |
+
"tradition": parsed_json.get('tradition', ''),
|
| 202 |
+
"theme": parsed_json.get('theme', ''),
|
| 203 |
"generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 204 |
}
|
| 205 |
except Exception as e:
|
| 206 |
log_message(f"❌ Error parsing quote result: {str(e)}", "error")
|
| 207 |
+
log_message("⚠️ Falling back to default quote", "warning")
|
| 208 |
return self._get_fallback_quote()
|
| 209 |
|
| 210 |
def generate_image(self, quote, tradition, theme):
|
|
|
|
| 256 |
|
| 257 |
music_prompts = {
|
| 258 |
"Buddhism": {
|
| 259 |
+
"Inner Peace": "Tibetan singing bowls and gentle bells with peaceful ambient drones, meditative and serene",
|
| 260 |
+
"Mindfulness": "Zen flute melodies with soft water sounds, creating a mindful atmosphere",
|
| 261 |
+
"default": "Meditation bells with nature sounds, peaceful and calming"
|
| 262 |
},
|
| 263 |
"Hinduism": {
|
| 264 |
+
"Devotion": "Indian bansuri flute with gentle tabla rhythms, creating a devotional atmosphere",
|
| 265 |
+
"Wisdom": "Gentle sitar melodies with peaceful tanpura drone",
|
| 266 |
+
"default": "Sanskrit chants with soft instrumentation, peaceful and meditative"
|
| 267 |
},
|
| 268 |
"Modern Spirituality": {
|
| 269 |
+
"Awareness": "Ambient synthesizer with crystal bowls, creating a modern meditative atmosphere",
|
| 270 |
+
"Growth": "Uplifting piano melodies with gentle ambient pads",
|
| 271 |
+
"default": "Modern meditation music with nature sounds and gentle electronics"
|
| 272 |
},
|
| 273 |
"default": {
|
| 274 |
+
"default": "Peaceful ambient music with gentle bells and subtle harmonies"
|
| 275 |
}
|
| 276 |
}
|
| 277 |
|
|
|
|
| 279 |
prompt = tradition_prompts.get(theme, tradition_prompts["default"])
|
| 280 |
|
| 281 |
output = self.replicate_client.run(
|
| 282 |
+
"meta/musicgen:671ac645ce5e552cc63a54a2bbff63fcf798043055d2dac5fc9e36a837eedcfb", # Updated model version
|
| 283 |
input={
|
|
|
|
| 284 |
"prompt": prompt,
|
| 285 |
+
"model_version": "stereo-large", # Using stereo large model
|
| 286 |
+
"output_format": "mp3",
|
| 287 |
+
"normalization_strategy": "peak",
|
| 288 |
+
"duration": 15 # Length in seconds
|
| 289 |
}
|
| 290 |
)
|
| 291 |
|