cryogenic22 commited on
Commit
4f36ea4
·
verified ·
1 Parent(s): 4aef699

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -47,9 +47,10 @@ class ContentGenerator:
47
  traditions = SpiritualThemes.TRADITIONS[tradition_category]
48
  themes = random.sample(SpiritualThemes.THEMES, 2)
49
  style = random.choice(SpiritualThemes.QUOTE_STYLES)
50
- return f"""Focus on {tradition_category} wisdom, particularly from {', '.join(traditions)}.
51
- Explore themes of {themes[0]} and {themes[1]} in a {style} style.
52
- Ensure the quote is profound yet accessible for social media."""
 
53
 
54
  def _get_fallback_quote(self):
55
  fallback_quotes = [
@@ -76,24 +77,32 @@ class ContentGenerator:
76
  model="gpt-4",
77
  messages=[{
78
  "role": "system",
79
- "content": "Generate spiritual quotes with author, tradition and theme."
80
  }, {
81
  "role": "user",
82
- "content": self._generate_prompt_variation() +
83
- "\nProvide quote in this format only:\nQUOTE:\nAUTHOR:\nTRADITION:\nTHEME:"
84
  }],
85
  temperature=0.7
86
  )
87
 
88
  text = response.choices[0].message.content
89
- result = dict(line.split(':', 1) for line in text.strip().split('\n') if ':' in line)
90
- return {
91
- "text": result.get('quote', '').strip(),
92
- "author": result.get('author', '').strip(),
93
- "tradition": result.get('tradition', '').strip(),
94
- "theme": result.get('theme', '').strip(),
 
 
 
 
 
95
  "generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
96
  }
 
 
 
 
97
  except Exception as e:
98
  log_message(f"❌ Quote generation failed: {str(e)}")
99
  return self._get_fallback_quote()
 
47
  traditions = SpiritualThemes.TRADITIONS[tradition_category]
48
  themes = random.sample(SpiritualThemes.THEMES, 2)
49
  style = random.choice(SpiritualThemes.QUOTE_STYLES)
50
+ return f"""Generate a spiritual quote from {tradition_category} wisdom tradition.
51
+ Focus on themes of {themes[0]} and {themes[1]}.
52
+ Make it profound yet accessible.
53
+ Format: Return only the quote text on first line, then author name on second line."""
54
 
55
  def _get_fallback_quote(self):
56
  fallback_quotes = [
 
77
  model="gpt-4",
78
  messages=[{
79
  "role": "system",
80
+ "content": "Generate a spiritual quote with attribution."
81
  }, {
82
  "role": "user",
83
+ "content": self._generate_prompt_variation()
 
84
  }],
85
  temperature=0.7
86
  )
87
 
88
  text = response.choices[0].message.content
89
+ lines = text.split('\n')
90
+ quote_text = lines[0] if lines else ""
91
+ author = lines[1].replace('-', '').strip() if len(lines) > 1 else "Unknown"
92
+ tradition = random.choice(list(SpiritualThemes.TRADITIONS.keys()))
93
+ theme = random.choice(SpiritualThemes.THEMES)
94
+
95
+ result = {
96
+ "text": quote_text,
97
+ "author": author,
98
+ "tradition": tradition,
99
+ "theme": theme,
100
  "generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
101
  }
102
+
103
+ log_message(f"✨ Generated quote: {quote_text}")
104
+ return result
105
+
106
  except Exception as e:
107
  log_message(f"❌ Quote generation failed: {str(e)}")
108
  return self._get_fallback_quote()