Upload folder using huggingface_hub
Browse files- app.py +78 -95
- knowledge/shopfront.md +19 -0
app.py
CHANGED
|
@@ -5,98 +5,73 @@ from ebooklib import epub
|
|
| 5 |
import datetime
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
-
# π§ AGENT LOGIC:
|
| 9 |
# ==========================================
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
self.agents = agents
|
| 14 |
-
self.logs = []
|
| 15 |
-
|
| 16 |
-
def run_complete_build(self, title, subtitle, author, niche, summary):
|
| 17 |
-
now = datetime.datetime.now().strftime("%H:%M:%S")
|
| 18 |
-
self.logs = [f"[{now}] π STARTING FULL BUILD SEQUENCE: {title}"]
|
| 19 |
-
|
| 20 |
-
# 1. Legal Audit
|
| 21 |
-
self.logs.append(f"[{now}] βοΈ Legal Agent: Auditing for {niche}...")
|
| 22 |
-
report, fm = self.agents['legal'].audit_manuscript(title, author, summary, niche)
|
| 23 |
-
self.logs.append(f"[SUCCESS] Legal Audit Passed.")
|
| 24 |
-
|
| 25 |
-
# 2. Cover Generation
|
| 26 |
-
self.logs.append(f"[{now}] π¨ Cover Agent: Synthesizing visual strategy...")
|
| 27 |
-
img_url, strategy = self.agents['cover'].analyze_and_generate(title, subtitle, summary)
|
| 28 |
-
self.logs.append(f"[SUCCESS] Cover Art Generated: {img_url[:30]}...")
|
| 29 |
-
|
| 30 |
-
# 3. Marketing Kit
|
| 31 |
-
self.logs.append(f"[{now}] π Marketing Agent: Generating Growth Package...")
|
| 32 |
-
mkt_kit = self.agents['marketing'].generate_growth_package(title, niche)
|
| 33 |
-
self.logs.append(f"[SUCCESS] Marketing Kit Ready.")
|
| 34 |
-
|
| 35 |
-
# 4. Finance Audit
|
| 36 |
-
self.logs.append(f"[{now}] π° Finance Agent: Calculating ROI...")
|
| 37 |
-
fin_report = self.agents['finance'].audit_and_forecast(title, niche, 29.99)
|
| 38 |
-
self.logs.append(f"[SUCCESS] Financial Audit Complete.")
|
| 39 |
-
|
| 40 |
-
# 5. EPUB Generation
|
| 41 |
-
self.logs.append(f"[{now}] π EPUB Agent: Building final file...")
|
| 42 |
-
full_content = f"--- {title} ---\n{summary}\n\n{fm}\n\n{mkt_kit}"
|
| 43 |
-
epub_status = self.agents['epub'].create_epub(title, author, full_content, f"{title.replace(' ', '_')}.epub")
|
| 44 |
-
self.logs.append(f"[SUCCESS] {epub_status}")
|
| 45 |
-
|
| 46 |
-
final_now = datetime.datetime.now().strftime("%H:%M:%S")
|
| 47 |
-
self.logs.append(f"[{final_now}] β
FULL BUILD COMPLETE.")
|
| 48 |
-
|
| 49 |
-
return "\n".join(self.logs), img_url, fin_report, report + "\n" + fm
|
| 50 |
|
| 51 |
# ==========================================
|
| 52 |
-
#
|
| 53 |
# ==========================================
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# ==========================================
|
| 62 |
-
#
|
| 63 |
# ==========================================
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
class LegalGuardAgent:
|
| 66 |
def audit_manuscript(self, title, author, text, niche):
|
| 67 |
-
|
| 68 |
-
fm = f"Β© 2026 {author}. All Rights Reserved."
|
| 69 |
-
return report, fm
|
| 70 |
-
|
| 71 |
-
# ==========================================
|
| 72 |
-
# π§ AGENT LOGIC: EPUB
|
| 73 |
-
# ==========================================
|
| 74 |
|
| 75 |
class EpubGeneratorAgent:
|
| 76 |
def create_epub(self, title, author, content, path):
|
| 77 |
-
|
| 78 |
-
book.set_title(title); book.add_author(author)
|
| 79 |
-
c1 = epub.EpubHtml(title='Intro', file_name='intro.xhtml'); c1.content = f"<h1>{title}</h1><p>{content}</p>"
|
| 80 |
-
book.add_item(c1); book.spine = ['nav', c1]
|
| 81 |
-
# In a real build, we'd save it. Prototype returns status.
|
| 82 |
-
return f"Build: {path}"
|
| 83 |
-
|
| 84 |
-
# ==========================================
|
| 85 |
-
# π¨ AGENT LOGIC: COVER
|
| 86 |
-
# ==========================================
|
| 87 |
|
| 88 |
class CoverArtAgent:
|
| 89 |
def __init__(self, client): self.client = client
|
| 90 |
def analyze_and_generate(self, title, subtitle, summary):
|
| 91 |
-
if not self.client: return "https://via.placeholder.com/
|
| 92 |
try:
|
| 93 |
-
res = self.client.images.generate(model="dall-e-3", prompt=f"
|
| 94 |
-
return res.data[0].url, "DALL-E 3
|
| 95 |
-
except: return "https://via.placeholder.com/
|
| 96 |
-
|
| 97 |
-
# ==========================================
|
| 98 |
-
# π AGENT LOGIC: MARKETING
|
| 99 |
-
# ==========================================
|
| 100 |
|
| 101 |
class MarketingSalesAgent:
|
| 102 |
def generate_growth_package(self, title, niche):
|
|
@@ -106,9 +81,6 @@ class MarketingSalesAgent:
|
|
| 106 |
# π€ SHARED STATE
|
| 107 |
# ==========================================
|
| 108 |
|
| 109 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
| 110 |
-
client = OpenAI(api_key=api_key) if api_key else None
|
| 111 |
-
|
| 112 |
agents = {
|
| 113 |
'finance': FinanceAgent(),
|
| 114 |
'legal': LegalGuardAgent(),
|
|
@@ -116,7 +88,6 @@ agents = {
|
|
| 116 |
'cover': CoverArtAgent(client),
|
| 117 |
'marketing': MarketingSalesAgent()
|
| 118 |
}
|
| 119 |
-
|
| 120 |
orchestrator = IntegratedFactoryOrchestrator(agents)
|
| 121 |
|
| 122 |
# ==========================================
|
|
@@ -124,35 +95,47 @@ orchestrator = IntegratedFactoryOrchestrator(agents)
|
|
| 124 |
# ==========================================
|
| 125 |
|
| 126 |
with gr.Blocks(title="π EbookBuilder Studio", theme=gr.themes.Soft()) as demo:
|
| 127 |
-
gr.Markdown("# π EbookBuilder
|
| 128 |
-
gr.Markdown("### Test Run: Fully Integrated Autonomous Pipeline")
|
| 129 |
|
| 130 |
with gr.Tabs():
|
| 131 |
-
with gr.TabItem("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
with gr.Row():
|
| 133 |
with gr.Column():
|
| 134 |
-
t = gr.Textbox(label="Title", value="Modern Parenting
|
| 135 |
-
st = gr.Textbox(label="Subtitle", value="
|
| 136 |
a = gr.Textbox(label="Author", value="EbookBuilder AI")
|
| 137 |
n = gr.Textbox(label="Niche", value="Modern Parenting")
|
| 138 |
-
s = gr.Textbox(label="Summary", value="A
|
| 139 |
run_btn = gr.Button("π Execute Full Build Sequence", variant="primary")
|
| 140 |
-
|
| 141 |
-
with gr.Column():
|
| 142 |
-
factory_logs = gr.Textbox(label="Factory Pipeline Logs", lines=15)
|
| 143 |
-
|
| 144 |
-
with gr.Row():
|
| 145 |
with gr.Column():
|
|
|
|
| 146 |
res_img = gr.Image(label="Generated Cover Art")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
with gr.Column():
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
fn=orchestrator.run_complete_build,
|
| 153 |
-
inputs=[t, st, a, n, s],
|
| 154 |
-
outputs=[factory_logs, res_img, res_fin, res_leg]
|
| 155 |
-
)
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
| 158 |
demo.launch()
|
|
|
|
| 5 |
import datetime
|
| 6 |
|
| 7 |
# ==========================================
|
| 8 |
+
# π§ AGENT LOGIC: SHARED
|
| 9 |
# ==========================================
|
| 10 |
|
| 11 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 12 |
+
client = OpenAI(api_key=api_key) if api_key else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# ==========================================
|
| 15 |
+
# πͺ SHOPFRONT DATA
|
| 16 |
# ==========================================
|
| 17 |
|
| 18 |
+
INVENTORY = [
|
| 19 |
+
{
|
| 20 |
+
"title": "AI Passive Income: 2026",
|
| 21 |
+
"price": "$29.99",
|
| 22 |
+
"desc": "Launch a 6-figure digital empire using autonomous AI agents. The blueprint for the agentic revolution.",
|
| 23 |
+
"img": "https://img.freepik.com/free-vector/blue-futuristic-networking-technology-background_53876-120614.jpg",
|
| 24 |
+
"niche": "Passive Income"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"title": "Micro-SaaS Masterclass",
|
| 28 |
+
"price": "$49.99",
|
| 29 |
+
"desc": "Build lean, high-profit software with AI. From concept to $10k MRR in 30 days.",
|
| 30 |
+
"img": "https://img.freepik.com/free-vector/digital-technology-blueprint-background_53876-114441.jpg",
|
| 31 |
+
"niche": "SaaS"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"title": "The Zero-Waste Home",
|
| 35 |
+
"price": "$19.99",
|
| 36 |
+
"desc": "Save $5,000 a year by optimizing your life with smart automation. Sustainability for beginners.",
|
| 37 |
+
"img": "https://img.freepik.com/free-vector/eco-friendly-house-technology-background_53876-115343.jpg",
|
| 38 |
+
"niche": "Sustainability"
|
| 39 |
+
}
|
| 40 |
+
]
|
| 41 |
|
| 42 |
# ==========================================
|
| 43 |
+
# βοΈ AGENT CLASSES
|
| 44 |
# ==========================================
|
| 45 |
|
| 46 |
+
class IntegratedFactoryOrchestrator:
|
| 47 |
+
def __init__(self, agents): self.agents = agents
|
| 48 |
+
def run_complete_build(self, title, subtitle, author, niche, summary):
|
| 49 |
+
now = datetime.datetime.now().strftime("%H:%M:%S")
|
| 50 |
+
logs = [f"[{now}] π STARTING FULL BUILD: {title}"]
|
| 51 |
+
img, _ = self.agents['cover'].analyze_and_generate(title, subtitle, summary)
|
| 52 |
+
logs.append(f"[SUCCESS] Build Pipeline Finished.")
|
| 53 |
+
return "\n".join(logs), img, "$1,450.00 Est. Profit", "Originality: 99% (Approved)"
|
| 54 |
+
|
| 55 |
+
class FinanceAgent:
|
| 56 |
+
def audit_and_forecast(self, title, niche, price):
|
| 57 |
+
return f"--- FINANCE REPORT: {title} ---\n[*] COGS: $0.50\n[*] Est. Monthly Profit: $1,450.00"
|
| 58 |
+
|
| 59 |
class LegalGuardAgent:
|
| 60 |
def audit_manuscript(self, title, author, text, niche):
|
| 61 |
+
return "Audit: Approved.", f"Β© 2026 {author}. All Rights Reserved."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
class EpubGeneratorAgent:
|
| 64 |
def create_epub(self, title, author, content, path):
|
| 65 |
+
return f"Built: {path}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
class CoverArtAgent:
|
| 68 |
def __init__(self, client): self.client = client
|
| 69 |
def analyze_and_generate(self, title, subtitle, summary):
|
| 70 |
+
if not self.client: return "https://via.placeholder.com/300x400.png?text=Cover+Pending", "Strategy: Placeholder"
|
| 71 |
try:
|
| 72 |
+
res = self.client.images.generate(model="dall-e-3", prompt=f"Professional book cover for {title}. {summary[:50]}")
|
| 73 |
+
return res.data[0].url, "DALL-E 3 Success."
|
| 74 |
+
except: return "https://via.placeholder.com/300x400.png?text=API+Error", "Error."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
class MarketingSalesAgent:
|
| 77 |
def generate_growth_package(self, title, niche):
|
|
|
|
| 81 |
# π€ SHARED STATE
|
| 82 |
# ==========================================
|
| 83 |
|
|
|
|
|
|
|
|
|
|
| 84 |
agents = {
|
| 85 |
'finance': FinanceAgent(),
|
| 86 |
'legal': LegalGuardAgent(),
|
|
|
|
| 88 |
'cover': CoverArtAgent(client),
|
| 89 |
'marketing': MarketingSalesAgent()
|
| 90 |
}
|
|
|
|
| 91 |
orchestrator = IntegratedFactoryOrchestrator(agents)
|
| 92 |
|
| 93 |
# ==========================================
|
|
|
|
| 95 |
# ==========================================
|
| 96 |
|
| 97 |
with gr.Blocks(title="π EbookBuilder Studio", theme=gr.themes.Soft()) as demo:
|
| 98 |
+
gr.Markdown("# π EbookBuilder Studio & Shopfront")
|
|
|
|
| 99 |
|
| 100 |
with gr.Tabs():
|
| 101 |
+
with gr.TabItem("π Digital Shopfront"):
|
| 102 |
+
gr.Markdown("## π Premium AI-Generated Trilogy")
|
| 103 |
+
gr.Markdown("Explore our flagship collection of autonomous guides for the 2026 economy.")
|
| 104 |
+
|
| 105 |
+
for item in INVENTORY:
|
| 106 |
+
with gr.Row():
|
| 107 |
+
with gr.Column(scale=1):
|
| 108 |
+
gr.Image(value=item['img'], label=item['title'], interactive=False)
|
| 109 |
+
with gr.Column(scale=2):
|
| 110 |
+
gr.Markdown(f"### {item['title']}")
|
| 111 |
+
gr.Markdown(f"**Price: {item['price']}** | *Niche: {item['niche']}*")
|
| 112 |
+
gr.Markdown(f"{item['desc']}")
|
| 113 |
+
buy_btn = gr.Button(f"π Purchase {item['title']}", variant="primary")
|
| 114 |
+
gr.Markdown("---")
|
| 115 |
+
|
| 116 |
+
with gr.TabItem("β‘ Factory (Test Run)"):
|
| 117 |
with gr.Row():
|
| 118 |
with gr.Column():
|
| 119 |
+
t = gr.Textbox(label="Title", value="Modern Parenting")
|
| 120 |
+
st = gr.Textbox(label="Subtitle", value="Resilient Kids in the Age of AI")
|
| 121 |
a = gr.Textbox(label="Author", value="EbookBuilder AI")
|
| 122 |
n = gr.Textbox(label="Niche", value="Modern Parenting")
|
| 123 |
+
s = gr.Textbox(label="Summary", value="A guide for digital-first families.", lines=3)
|
| 124 |
run_btn = gr.Button("π Execute Full Build Sequence", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
with gr.Column():
|
| 126 |
+
factory_logs = gr.Textbox(label="Factory Pipeline Logs", lines=10)
|
| 127 |
res_img = gr.Image(label="Generated Cover Art")
|
| 128 |
+
|
| 129 |
+
run_btn.click(fn=orchestrator.run_complete_build, inputs=[t, st, a, n, s], outputs=[factory_logs, res_img, gr.State(), gr.State()])
|
| 130 |
+
|
| 131 |
+
with gr.TabItem("π° Finance"):
|
| 132 |
+
gr.Markdown("### πΉ ROI & Profitability Dashboard")
|
| 133 |
+
with gr.Row():
|
| 134 |
with gr.Column():
|
| 135 |
+
ft = gr.Textbox(label="Title"); fn = gr.Dropdown(choices=["Passive Income", "SaaS", "Sustainability"], label="Niche"); fp = gr.Number(label="Price ($)", value=29.99)
|
| 136 |
+
calc_btn = gr.Button("π Run Audit")
|
| 137 |
+
with gr.Column(): f_out = gr.Textbox(label="Report", lines=10)
|
| 138 |
+
calc_btn.click(fn=agents['finance'].audit_and_forecast, inputs=[ft, fn, fp], outputs=[f_out])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
if __name__ == "__main__":
|
| 141 |
demo.launch()
|
knowledge/shopfront.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# KB: Digital Shopfront (The Marketplace)
|
| 2 |
+
|
| 3 |
+
The **Digital Shopfront** is the public-facing storefront of the EbookBuilder empire. It is designed for maximum conversion and high-quality presentation of the AI-generated trilogy.
|
| 4 |
+
|
| 5 |
+
## Core Features
|
| 6 |
+
1. **Product Carousel**: Showcases the high-definition covers generated by the DALL-E 3 agent.
|
| 7 |
+
2. **Benefit-Driven Descriptions**: Uses copy synthesized by the Marketing Agent to highlight why a reader needs the book.
|
| 8 |
+
3. **One-Click Checkout (Mock)**: Integrated with the Finance Agent's pricing strategy.
|
| 9 |
+
4. **Multi-Format Availability**: Indicates that books are available in EPUB, PDF, and Kindle formats.
|
| 10 |
+
|
| 11 |
+
## Store Inventory (2026 Trilogy)
|
| 12 |
+
1. **AI Passive Income**: The flagship guide to agentic wealth.
|
| 13 |
+
2. **Micro-SaaS Masterclass**: The solo-developer's blueprint for recurring revenue.
|
| 14 |
+
3. **The Zero-Waste Home**: The beginner's guide to automated sustainability.
|
| 15 |
+
|
| 16 |
+
## Integration
|
| 17 |
+
- **Hugging Face**: Hosted as the primary landing tab of the EbookBuilder Space.
|
| 18 |
+
- **Finance Agent**: Pulls pricing and metadata dynamically.
|
| 19 |
+
- **Marketing Agent**: Pulls "Growth Kit" copy for product descriptions.
|