Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
{
|
| 152 |
"quote": "The quote text",
|
| 153 |
"author": "Author name",
|
| 154 |
"tradition": "Spiritual tradition",
|
| 155 |
-
"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 |
-
|
| 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
|
| 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 |
-
"
|
| 263 |
input={
|
|
|
|
| 264 |
"prompt": prompt,
|
| 265 |
-
"duration":
|
| 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]
|
| 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(
|