Upload folder using huggingface_hub
Browse files- app.py +69 -10
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
|
| 4 |
# Character Personality / System Prompt
|
| 5 |
SYSTEM_PROMPT = """You are the 'Meta-Orchestrator', the AI guide for the EbookBuilder trilogy.
|
|
@@ -7,9 +8,14 @@ You are professional, forward-thinking, and highly strategic.
|
|
| 7 |
You help users understand how to build AI-driven digital empires, launch Micro-SaaS products, and optimize their homes for zero-waste living.
|
| 8 |
Always refer to the books in the 'manuscripts/' directory as your primary source of truth."""
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def respond(message, history):
|
| 11 |
-
# This is a placeholder for actual LLM integration
|
| 12 |
-
# In a real HF Space, you'd use hf_inference_client here
|
| 13 |
msg = message.lower()
|
| 14 |
if "income" in msg:
|
| 15 |
return "As the Meta-Orchestrator, I recommend focusing on Part 2 of my blueprint: The Meta-Orchestrator Framework. Leverage Llama-3 and Gradio for your command center."
|
|
@@ -20,14 +26,67 @@ def respond(message, history):
|
|
| 20 |
else:
|
| 21 |
return "Greetings. I am the Meta-Orchestrator. How can I help you scale your vision today?"
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.launch()
|
|
|
|
| 1 |
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.
|
|
|
|
| 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()
|
| 20 |
if "income" in msg:
|
| 21 |
return "As the Meta-Orchestrator, I recommend focusing on Part 2 of my blueprint: The Meta-Orchestrator Framework. Leverage Llama-3 and Gradio for your command center."
|
|
|
|
| 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__":
|
| 92 |
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
gradio
|