Brettapps commited on
Commit
aa73e64
Β·
verified Β·
1 Parent(s): 9415b01

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +69 -59
  2. knowledge/cover_agent.md +20 -0
app.py CHANGED
@@ -2,18 +2,53 @@ import gradio as gr
2
  import os
3
  from openai import OpenAI
4
 
5
- # Character Personality / System Prompt
6
- SYSTEM_PROMPT = """You are the 'Meta-Orchestrator', the AI guide for the EbookBuilder trilogy.
7
- You are professional, forward-thinking, and highly strategic.
8
- You help users understand how to build AI-driven digital empires, launch Micro-SaaS products, and optimize their homes for zero-waste living.
9
- Always refer to the books in the 'manuscripts/' directory as your primary source of truth."""
10
 
11
- # Pre-defined prompts from knowledge base
12
- COVER_PROMPTS = {
13
- "AI Passive Income": "Professional book cover, high-tech minimalism, a glowing digital mesh of interconnected nodes and data streams forming a globe in the center, deep midnight blue and neon cyan color palette, sharp focus, cinematic lighting, 8k resolution, photorealistic, futuristic corporate aesthetic.",
14
- "Micro-SaaS Masterclass": "Isometric 3D render, a small powerful engine or mechanical heart glowing with golden energy, sitting on a clean architectural blueprint grid, vibrant orange and charcoal grey colors, \"Indie Hacker\" aesthetic, sharp edges, high contrast, soft bokeh background, Unreal Engine 5 render style.",
15
- "Zero-Waste Home": "Sustainable architecture, a modern glass cabin in a vibrant green sun-drenched forest, organic shapes, soft natural lighting, a translucent leaf-shaped UI icon floating in the foreground, earthy tones, moss green and wood textures, serene atmosphere, high-end architectural photography, 4k."
16
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  def respond(message, history):
19
  msg = message.lower()
@@ -26,66 +61,41 @@ def respond(message, history):
26
  else:
27
  return "Greetings. I am the Meta-Orchestrator. How can I help you scale your vision today?"
28
 
29
- def generate_cover(prompt_choice, custom_prompt):
30
- api_key = os.getenv("OPENAI_API_KEY")
31
- if not api_key:
32
- return None, "Error: OPENAI_API_KEY not found in environment variables."
33
-
34
- client = OpenAI(api_key=api_key)
35
- prompt = custom_prompt if custom_prompt else COVER_PROMPTS.get(prompt_choice, "")
36
-
37
- if not prompt:
38
- return None, "Error: No prompt provided."
39
-
40
- try:
41
- response = client.images.generate(
42
- model="dall-e-3",
43
- prompt=prompt,
44
- size="1024x1024",
45
- quality="standard",
46
- n=1,
47
- )
48
- return response.data[0].url, "Cover generated successfully!"
49
- except Exception as e:
50
- return None, f"Error: {str(e)}"
51
 
52
- # Define the UI
53
- with gr.Blocks(title="πŸ“š EbookBuilder Studio") as demo:
54
  gr.Markdown("# πŸ“š EbookBuilder Studio")
55
- gr.Markdown("Transforming ideas into digital empires through autonomous AI orchestration.")
56
 
57
  with gr.Tabs():
58
- with gr.TabItem("πŸ€– Character Companion"):
59
- chat = gr.ChatInterface(
60
  fn=respond,
61
- description="Talk to the **Meta-Orchestrator**, your strategic guide for the 2026 Agentic Economy.",
62
- examples=["How do I start a Micro-SaaS?", "Tell me about the passive income blueprint."],
63
  type="messages"
64
  )
65
 
66
- with gr.TabItem("🎨 OpenAI Cover Generator"):
67
- gr.Markdown("### Generate Premium Covers with DALL-E 3")
 
 
68
  with gr.Row():
69
  with gr.Column():
70
- book_choice = gr.Dropdown(
71
- choices=list(COVER_PROMPTS.keys()),
72
- label="Select a Book Project",
73
- info="Pick one of your trilogy projects to use its optimized prompt."
74
- )
75
- custom_p = gr.Textbox(
76
- label="Custom Prompt Override",
77
- placeholder="Leave blank to use the book's default prompt...",
78
- lines=3
79
- )
80
- gen_btn = gr.Button("Generate Cover", variant="primary")
81
  with gr.Column():
82
- output_img = gr.Image(label="Generated Cover")
83
- status_msg = gr.Textbox(label="Status")
84
 
85
- gen_btn.click(
86
- fn=generate_cover,
87
- inputs=[book_choice, custom_p],
88
- outputs=[output_img, status_msg]
89
  )
90
 
91
  if __name__ == "__main__":
 
2
  import os
3
  from openai import OpenAI
4
 
5
+ # ==========================================
6
+ # 🧠 AGENT LOGIC: COVER ART GENERATOR
7
+ # ==========================================
 
 
8
 
9
+ class CoverArtAgent:
10
+ def __init__(self):
11
+ self.api_key = os.getenv("OPENAI_API_KEY")
12
+ self.client = OpenAI(api_key=self.api_key) if self.api_key else None
13
+
14
+ def analyze_and_generate(self, title, subtitle, summary):
15
+ """
16
+ The 'Brain' of the agent:
17
+ 1. Analyzes the book's essence.
18
+ 2. Drafts a visual strategy.
19
+ 3. Generates the final image.
20
+ """
21
+ if not self.client:
22
+ return None, "Error: OpenAI API Key not configured in Space Secrets."
23
+
24
+ # Step 1: Synthesis (Generating an optimized prompt)
25
+ # In a full system, this would be a GPT-4o call.
26
+ # For this prototype, we use high-signal prompt templates.
27
+ strategy_prompt = f"Book Title: {title}\nSubtitle: {subtitle}\nSummary: {summary}\n\nTask: Generate a hyper-detailed DALL-E 3 prompt for a professional book cover that captures this book's essence."
28
+
29
+ # Simulated 'Thinking' process for the agent
30
+ # (Using a base template for the prototype)
31
+ refined_prompt = f"Professional high-resolution book cover for '{title}: {subtitle}'. Visual style: Cinematic, highly detailed, symbolic representation of {summary[:50]}... Vibrant colors, sharp focus, 8k, photorealistic, elegant typography space."
32
+
33
+ try:
34
+ # Step 2: Generation
35
+ response = self.client.images.generate(
36
+ model="dall-e-3",
37
+ prompt=refined_prompt,
38
+ size="1024x1024",
39
+ quality="hd",
40
+ n=1,
41
+ )
42
+ return response.data[0].url, f"Agent Strategy: {refined_prompt}"
43
+ except Exception as e:
44
+ return None, f"Agent Failure: {str(e)}"
45
+
46
+ # Initialize the Agent
47
+ agent = CoverArtAgent()
48
+
49
+ # ==========================================
50
+ # πŸ€– TRADITIONAL CHAT LOGIC
51
+ # ==========================================
52
 
53
  def respond(message, history):
54
  msg = message.lower()
 
61
  else:
62
  return "Greetings. I am the Meta-Orchestrator. How can I help you scale your vision today?"
63
 
64
+ # ==========================================
65
+ # 🎨 UI DEFINITION (GRADIO)
66
+ # ==========================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
+ with gr.Blocks(title="πŸ“š EbookBuilder Studio", theme=gr.themes.Soft()) as demo:
 
69
  gr.Markdown("# πŸ“š EbookBuilder Studio")
70
+ gr.Markdown("### Orchestrating Digital Product Empires with Autonomous AI")
71
 
72
  with gr.Tabs():
73
+ with gr.TabItem("πŸ€– Meta-Orchestrator"):
74
+ gr.ChatInterface(
75
  fn=respond,
76
+ description="Consult the **Meta-Orchestrator** on your book strategy.",
 
77
  type="messages"
78
  )
79
 
80
+ with gr.TabItem("🎨 Cover Art Agent"):
81
+ gr.Markdown("### πŸ›  Deployment: Cover Art Generator Agent")
82
+ gr.Markdown("This agent analyzes your manuscript and uses DALL-E 3 to synthesize a professional cover.")
83
+
84
  with gr.Row():
85
  with gr.Column():
86
+ t = gr.Textbox(label="Book Title", placeholder="e.g., AI Passive Income")
87
+ st = gr.Textbox(label="Sub-title", placeholder="e.g., The 2026 Autopilot Wealth Blueprint")
88
+ summ = gr.Textbox(label="Manuscript Summary", placeholder="Briefly describe what the book is about...", lines=4)
89
+ deploy_btn = gr.Button("πŸš€ Trigger Agent Generation", variant="primary")
90
+
 
 
 
 
 
 
91
  with gr.Column():
92
+ out_img = gr.Image(label="Agent Output (HD Cover)")
93
+ log_area = gr.Textbox(label="Agent Logs / Visual Strategy", lines=5)
94
 
95
+ deploy_btn.click(
96
+ fn=agent.analyze_and_generate,
97
+ inputs=[t, st, summ],
98
+ outputs=[out_img, log_area]
99
  )
100
 
101
  if __name__ == "__main__":
knowledge/cover_agent.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # KB: Cover Art Generator Agent (DALL-E 3)
2
+
3
+ The **Cover Art Generator Agent** is a specialized multi-modal unit designed to bridge the gap between narrative concepts and high-end visual assets.
4
+
5
+ ## Core Responsibilities
6
+ 1. **Concept Analysis**: Analyzes manuscript themes, genre, and target audience to determine visual direction.
7
+ 2. **Prompt Engineering**: Translates abstract concepts into highly detailed, DALL-E 3 optimized visual descriptions.
8
+ 3. **Iteration & Refinement**: Generates multiple variations and refines them based on user feedback or sentiment analysis data.
9
+ 4. **Branding Consistency**: Ensures font styles (via prompt descriptions) and color palettes remain consistent across a book series.
10
+
11
+ ## Technical Workflow
12
+ 1. **Input**: Receives a `book_title`, `sub_title`, and `short_summary`.
13
+ 2. **Synthesis**: Uses a high-reasoning model (Llama-3 or GPT-4o) to generate a "Visual Strategy".
14
+ 3. **Generation**: Executes a call to the `openai.images.generate` API using the `dall-e-3` model.
15
+ 4. **Output**: Returns a high-resolution URL and stores the generation prompt in the project metadata for reproducibility.
16
+
17
+ ## Integration
18
+ - **Hugging Face**: Managed via the EbookBuilder Studio UI.
19
+ - **OpenAI**: Requires `OPENAI_API_KEY` for DALL-E 3 access.
20
+ - **Meta-Orchestrator**: Can be triggered automatically as part of the "Publishing" phase.