Upload folder using huggingface_hub
Browse files- app.py +69 -59
- 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 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 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 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
| 30 |
-
|
| 31 |
-
|
| 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 |
-
|
| 53 |
-
with gr.Blocks(title="π EbookBuilder Studio") as demo:
|
| 54 |
gr.Markdown("# π EbookBuilder Studio")
|
| 55 |
-
gr.Markdown("
|
| 56 |
|
| 57 |
with gr.Tabs():
|
| 58 |
-
with gr.TabItem("π€
|
| 59 |
-
|
| 60 |
fn=respond,
|
| 61 |
-
description="
|
| 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("π¨
|
| 67 |
-
gr.Markdown("###
|
|
|
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column():
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 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 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
-
fn=
|
| 87 |
-
inputs=[
|
| 88 |
-
outputs=[
|
| 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.
|