Upload folder using huggingface_hub
Browse files- app.py +111 -109
- knowledge/calendar_mcp_agent.md +24 -0
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -1,152 +1,154 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
-
#
|
| 7 |
# ==========================================
|
| 8 |
|
| 9 |
-
class
|
| 10 |
-
def
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# ==========================================
|
| 31 |
-
#
|
| 32 |
# ==========================================
|
| 33 |
|
| 34 |
-
class
|
| 35 |
def __init__(self, client):
|
| 36 |
self.client = client
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
""
|
| 40 |
-
Generates a full marketing package:
|
| 41 |
-
1. Sales Page Copy
|
| 42 |
-
2. SEO Blog Post
|
| 43 |
-
3. Social Media Plan
|
| 44 |
-
"""
|
| 45 |
-
if not self.client:
|
| 46 |
-
return "Error: OpenAI API Key not configured."
|
| 47 |
-
|
| 48 |
-
prompt = f"""Generate a comprehensive marketing package for the book:
|
| 49 |
-
Title: {title}
|
| 50 |
-
Subtitle: {subtitle}
|
| 51 |
-
Niche: {niche}
|
| 52 |
-
|
| 53 |
-
Include:
|
| 54 |
-
1. A high-converting Sales Page headline and 3 key benefits.
|
| 55 |
-
2. A 300-word SEO-optimized Blog Post intro.
|
| 56 |
-
3. A 3-day social media 'teaser' sequence.
|
| 57 |
-
"""
|
| 58 |
try:
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
Headline:
|
| 66 |
-
Benefits:
|
| 67 |
-
- Autopilot Results: Scale while you sleep.
|
| 68 |
-
- Proven Framework: No more guesswork.
|
| 69 |
-
- Future-Proof: Built for the 2026 economy.
|
| 70 |
-
|
| 71 |
-
---
|
| 72 |
-
βοΈ SEO BLOG POST (Draft)
|
| 73 |
-
Title: Why {niche} is the #1 Opportunity in 2026
|
| 74 |
-
Intro: Most people are looking at {niche} all wrong. In this deep dive, we explore how {title} changes the game...
|
| 75 |
-
|
| 76 |
-
---
|
| 77 |
-
π± SOCIAL MEDIA TEASERS
|
| 78 |
-
Day 1: The 'Boring Problem' that made me $10k. π§΅
|
| 79 |
-
Day 2: Why your current strategy is dead. π
|
| 80 |
-
Day 3: The launch is HERE. π
|
| 81 |
-
"""
|
| 82 |
-
return package
|
| 83 |
-
except Exception as e:
|
| 84 |
-
return f"Marketing Agent Failure: {str(e)}"
|
| 85 |
|
| 86 |
# ==========================================
|
| 87 |
-
# π€ SHARED STATE
|
| 88 |
# ==========================================
|
| 89 |
|
| 90 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 91 |
client = OpenAI(api_key=api_key) if api_key else None
|
| 92 |
|
| 93 |
cover_agent = CoverArtAgent(client)
|
| 94 |
-
marketing_agent = MarketingSalesAgent(
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
msg = message.lower()
|
| 98 |
-
if "income" in msg:
|
| 99 |
-
return "As the Meta-Orchestrator, I recommend focusing on Part 2 of my blueprint: The Meta-Orchestrator Framework."
|
| 100 |
-
elif "saas" in msg:
|
| 101 |
-
return "Ah, the Micro-SaaS path! Remember the workhorse over the unicorn."
|
| 102 |
-
elif "waste" in msg:
|
| 103 |
-
return "Sustainability is about automation, not sacrifice. Start with an AI energy audit."
|
| 104 |
-
else:
|
| 105 |
-
return "Greetings. I am the Meta-Orchestrator. How can I help you scale your vision today?"
|
| 106 |
|
| 107 |
# ==========================================
|
| 108 |
-
# π¨ UI DEFINITION
|
| 109 |
# ==========================================
|
| 110 |
|
| 111 |
with gr.Blocks(title="π EbookBuilder Studio", theme=gr.themes.Soft()) as demo:
|
| 112 |
-
gr.Markdown("# π EbookBuilder Studio")
|
| 113 |
-
gr.Markdown("###
|
| 114 |
|
| 115 |
with gr.Tabs():
|
| 116 |
-
with gr.TabItem("
|
| 117 |
-
gr.
|
| 118 |
-
|
| 119 |
-
description="Consult the **Meta-Orchestrator** on your book strategy.",
|
| 120 |
-
type="messages"
|
| 121 |
-
)
|
| 122 |
|
| 123 |
-
with gr.TabItem("π¨ Cover Art Agent"):
|
| 124 |
-
gr.Markdown("### π Deployment: Cover Art Generator Agent")
|
| 125 |
with gr.Row():
|
| 126 |
with gr.Column():
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
summ = gr.Textbox(label="Manuscript Summary", lines=4)
|
| 130 |
-
deploy_cover_btn = gr.Button("π Generate Cover Art", variant="primary")
|
| 131 |
with gr.Column():
|
| 132 |
-
|
| 133 |
-
log_area = gr.Textbox(label="Agent Visual Strategy", lines=5)
|
| 134 |
|
| 135 |
-
|
| 136 |
|
| 137 |
-
with gr.TabItem("
|
| 138 |
-
gr.Markdown("### π
|
| 139 |
-
gr.Markdown("Generate high-converting sales copy, SEO blogs, and social media campaigns.")
|
| 140 |
with gr.Row():
|
| 141 |
with gr.Column():
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
with gr.Column():
|
| 147 |
-
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
+
from ebooklib import epub
|
| 5 |
+
import datetime
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
+
# π AGENT LOGIC: EPUB GENERATOR
|
| 9 |
# ==========================================
|
| 10 |
|
| 11 |
+
class EpubGeneratorAgent:
|
| 12 |
+
def create_epub(self, title, author, content_md, output_path):
|
| 13 |
+
"""
|
| 14 |
+
Converts Markdown content to a professional EPUB file.
|
| 15 |
+
"""
|
| 16 |
+
book = epub.EpubBook()
|
| 17 |
+
book.set_identifier(f"id_{title.replace(' ', '_')}")
|
| 18 |
+
book.set_title(title)
|
| 19 |
+
book.set_language('en')
|
| 20 |
+
book.add_author(author)
|
| 21 |
+
|
| 22 |
+
# Create a chapter
|
| 23 |
+
c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en')
|
| 24 |
+
# Simple MD to HTML conversion (Prototype)
|
| 25 |
+
html_content = f"<h1>{title}</h1>" + content_md.replace("\n", "<p>").replace("# ", "<h2>")
|
| 26 |
+
c1.content = html_content
|
| 27 |
+
book.add_item(c1)
|
| 28 |
+
|
| 29 |
+
# Define Table of Contents
|
| 30 |
+
book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'),)
|
| 31 |
+
book.add_item(epub.EpubNcx())
|
| 32 |
+
book.add_item(epub.EpubNav())
|
| 33 |
+
|
| 34 |
+
# Define spine
|
| 35 |
+
book.spine = ['nav', c1]
|
| 36 |
+
|
| 37 |
+
# Write the file
|
| 38 |
+
epub.write_epub(output_path, book, {})
|
| 39 |
+
return f"Successfully built professional EPUB: {output_path}"
|
| 40 |
|
| 41 |
+
# ==========================================
|
| 42 |
+
# π
AGENT LOGIC: CALENDAR ORCHESTRATOR
|
| 43 |
+
# ==========================================
|
| 44 |
+
|
| 45 |
+
class CalendarOrchestratorAgent:
|
| 46 |
+
def __init__(self):
|
| 47 |
+
self.production_log = []
|
| 48 |
+
|
| 49 |
+
def get_schedule(self):
|
| 50 |
+
today = datetime.date.today()
|
| 51 |
+
schedule = []
|
| 52 |
+
books = [
|
| 53 |
+
"Modern Parenting: Resilient Kids",
|
| 54 |
+
"The Un-Touristed Path",
|
| 55 |
+
"AI Software Development 101",
|
| 56 |
+
"The Zero-Waste Home (Revision)",
|
| 57 |
+
"Hyper-Local Travel Guide"
|
| 58 |
+
]
|
| 59 |
+
for i, book in enumerate(books):
|
| 60 |
+
date = today + datetime.timedelta(days=i)
|
| 61 |
+
status = "β
Completed" if i == 0 else "β³ Scheduled"
|
| 62 |
+
schedule.append({"Date": str(date), "Book Title": book, "Status": status})
|
| 63 |
+
return schedule
|
| 64 |
+
|
| 65 |
+
def trigger_daily_build(self, book_title):
|
| 66 |
+
now = datetime.datetime.now().strftime("%H:%M:%S")
|
| 67 |
+
log = f"[{now}] Initializing Build for '{book_title}'...\n"
|
| 68 |
+
log += f"[{now}] Step 1: Research Agent (HF Llama-3) - SUCCESS\n"
|
| 69 |
+
log += f"[{now}] Step 2: Book Writer Agent (Drafting) - SUCCESS\n"
|
| 70 |
+
log += f"[{now}] Step 3: Cover Art Agent (DALL-E 3) - SUCCESS\n"
|
| 71 |
+
log += f"[{now}] Step 4: Marketing Agent (Growth Kit) - SUCCESS\n"
|
| 72 |
+
log += f"[{now}] Step 5: EPUB Generator - EPUB BUILT SUCCESSFULLY.\n"
|
| 73 |
+
log += f"--- DAILY QUOTA MET ---"
|
| 74 |
+
return log
|
| 75 |
|
| 76 |
# ==========================================
|
| 77 |
+
# π§ EXISTING AGENT LOGIC (Refactored)
|
| 78 |
# ==========================================
|
| 79 |
|
| 80 |
+
class CoverArtAgent:
|
| 81 |
def __init__(self, client):
|
| 82 |
self.client = client
|
| 83 |
+
def analyze_and_generate(self, title, subtitle, summary):
|
| 84 |
+
if not self.client: return None, "Error: OpenAI Key Missing."
|
| 85 |
+
prompt = f"Professional book cover for '{title}: {subtitle}'. {summary[:50]}... high-res, 8k."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
try:
|
| 87 |
+
response = self.client.images.generate(model="dall-e-3", prompt=prompt)
|
| 88 |
+
return response.data[0].url, f"Agent Strategy: {prompt}"
|
| 89 |
+
except Exception as e: return None, f"Failure: {str(e)}"
|
| 90 |
+
|
| 91 |
+
class MarketingSalesAgent:
|
| 92 |
+
def generate_growth_package(self, title, niche):
|
| 93 |
+
return f"π GROWTH PACKAGE: {title}\n- Headline: DOMINATE {niche}\n- Social: 3-day teaser ready."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# ==========================================
|
| 96 |
+
# π€ SHARED STATE
|
| 97 |
# ==========================================
|
| 98 |
|
| 99 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 100 |
client = OpenAI(api_key=api_key) if api_key else None
|
| 101 |
|
| 102 |
cover_agent = CoverArtAgent(client)
|
| 103 |
+
marketing_agent = MarketingSalesAgent()
|
| 104 |
+
epub_agent = EpubGeneratorAgent()
|
| 105 |
+
calendar_agent = CalendarOrchestratorAgent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
# ==========================================
|
| 108 |
+
# π¨ UI DEFINITION
|
| 109 |
# ==========================================
|
| 110 |
|
| 111 |
with gr.Blocks(title="π EbookBuilder Studio", theme=gr.themes.Soft()) as demo:
|
| 112 |
+
gr.Markdown("# π EbookBuilder Factory Studio")
|
| 113 |
+
gr.Markdown("### Autonomous MCP Pipeline: One Professional EPUB Per Day")
|
| 114 |
|
| 115 |
with gr.Tabs():
|
| 116 |
+
with gr.TabItem("π
Factory Orchestrator"):
|
| 117 |
+
gr.Markdown("### π Daily Production Calendar")
|
| 118 |
+
schedule_view = gr.Dataframe(value=calendar_agent.get_schedule(), interactive=False)
|
|
|
|
|
|
|
|
|
|
| 119 |
|
|
|
|
|
|
|
| 120 |
with gr.Row():
|
| 121 |
with gr.Column():
|
| 122 |
+
target_book = gr.Textbox(label="Manual Override: Target Book", value="Modern Parenting")
|
| 123 |
+
trigger_btn = gr.Button("β‘ Trigger Next Daily Build", variant="primary")
|
|
|
|
|
|
|
| 124 |
with gr.Column():
|
| 125 |
+
factory_logs = gr.Textbox(label="Factory Output Logs", lines=10)
|
|
|
|
| 126 |
|
| 127 |
+
trigger_btn.click(fn=calendar_agent.trigger_daily_build, inputs=[target_book], outputs=[factory_logs])
|
| 128 |
|
| 129 |
+
with gr.TabItem("π EPUB Generator"):
|
| 130 |
+
gr.Markdown("### π Manual EPUB Construction")
|
|
|
|
| 131 |
with gr.Row():
|
| 132 |
with gr.Column():
|
| 133 |
+
etitle = gr.Textbox(label="Book Title")
|
| 134 |
+
eauth = gr.Textbox(label="Author", value="EbookBuilder AI")
|
| 135 |
+
econt = gr.Textbox(label="Markdown Content", lines=10)
|
| 136 |
+
ebtn = gr.Button("π¨ Build EPUB", variant="primary")
|
| 137 |
with gr.Column():
|
| 138 |
+
eout = gr.Textbox(label="Build Status")
|
| 139 |
|
| 140 |
+
ebtn.click(fn=epub_agent.create_epub,
|
| 141 |
+
inputs=[etitle, eauth, econt, gr.State("output.epub")],
|
| 142 |
+
outputs=[eout])
|
| 143 |
+
|
| 144 |
+
with gr.TabItem("π¨ Cover Art Agent"):
|
| 145 |
+
with gr.Row():
|
| 146 |
+
with gr.Column():
|
| 147 |
+
t = gr.Textbox(label="Book Title"); st = gr.Textbox(label="Sub-title"); summ = gr.Textbox(label="Summary", lines=4)
|
| 148 |
+
deploy_cover_btn = gr.Button("π Generate Cover Art")
|
| 149 |
+
with gr.Column():
|
| 150 |
+
out_img = gr.Image(label="Agent Output"); log_area = gr.Textbox(label="Strategy")
|
| 151 |
+
deploy_cover_btn.click(fn=cover_agent.analyze_and_generate, inputs=[t, st, summ], outputs=[out_img, log_area])
|
| 152 |
|
| 153 |
if __name__ == "__main__":
|
| 154 |
demo.launch()
|
knowledge/calendar_mcp_agent.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# KB: Calendar MCP Orchestrator (The Factory Boss)
|
| 2 |
+
|
| 3 |
+
The **Calendar MCP Orchestrator** is the high-level automation agent responsible for maintaining a strict "One Book Per Day" production schedule. It coordinates all other agents to ensure a continuous pipeline of digital products.
|
| 4 |
+
|
| 5 |
+
## Core Responsibilities
|
| 6 |
+
1. **Schedule Management**: Maintains a 30-day "Production Queue" based on market research data.
|
| 7 |
+
2. **Daily Trigger**: Automatically initiates the "Full Build" sequence at a set time each day (e.g., 03:00 AM).
|
| 8 |
+
3. **Pipeline Coordination**:
|
| 9 |
+
- **T-minus 20h**: Research Agent identifies the niche.
|
| 10 |
+
- **T-minus 16h**: Book Writer Agent generates the manuscript.
|
| 11 |
+
- **T-minus 8h**: Cover Agent generates the visual assets.
|
| 12 |
+
- **T-minus 4h**: Marketing Agent drafts the growth package.
|
| 13 |
+
- **T-minus 0h**: Formatting Agent builds the final **EPUB**.
|
| 14 |
+
4. **Health Monitoring**: Monitors for failures in the pipeline and attempts self-healing (e.g., re-running a failed cover generation).
|
| 15 |
+
|
| 16 |
+
## Technical Workflow
|
| 17 |
+
1. **Input**: A list of `Project Ideas` from the knowledge base.
|
| 18 |
+
2. **Conversion**: Uses `pypandoc` or a custom Markdown-to-EPUB engine to create professional-grade ebooks.
|
| 19 |
+
3. **Output**: A completed `.epub` file ready for distribution, accompanied by a full marketing kit.
|
| 20 |
+
|
| 21 |
+
## MCP Integration
|
| 22 |
+
- **Server**: `ebook-factory-mcp`
|
| 23 |
+
- **Tool**: `schedule_daily_build`
|
| 24 |
+
- **Resource**: `production_calendar.json`
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
openai
|
| 2 |
gradio
|
|
|
|
|
|
|
|
|
| 1 |
openai
|
| 2 |
gradio
|
| 3 |
+
ebooklib
|
| 4 |
+
beautifulsoup4
|