Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -3,20 +3,49 @@ import gradio as gr
|
|
| 3 |
from fastmcp import FastMCP
|
| 4 |
from openai import OpenAI
|
| 5 |
from memory_sync import save_to_databank, load_from_databank, get_embeddings
|
|
|
|
| 6 |
from ebook_pipeline import create_ebook_files
|
| 7 |
|
| 8 |
# Load Environment Variables
|
| 9 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
| 10 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
|
| 11 |
|
| 12 |
-
# Initialize
|
| 13 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
mcp = FastMCP("Aussie Agent Hub")
|
| 17 |
|
| 18 |
# --- MCP TOOLS ---
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@mcp.tool()
|
| 21 |
def generate_ebook(title: str, author: str, chapters: list) -> str:
|
| 22 |
"""Generate EPUB and PDF files from a list of chapters (title and content)."""
|
|
|
|
| 3 |
from fastmcp import FastMCP
|
| 4 |
from openai import OpenAI
|
| 5 |
from memory_sync import save_to_databank, load_from_databank, get_embeddings
|
| 6 |
+
import stripe
|
| 7 |
from ebook_pipeline import create_ebook_files
|
| 8 |
|
| 9 |
# Load Environment Variables
|
| 10 |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
| 11 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 12 |
+
STRIPE_API_KEY = os.environ.get("STRIPE_API_KEY")
|
| 13 |
|
| 14 |
+
# Initialize Clients
|
| 15 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 16 |
+
if STRIPE_API_KEY:
|
| 17 |
+
stripe.api_key = STRIPE_API_KEY
|
| 18 |
|
| 19 |
+
# ... (MCP Server Init)
|
|
|
|
| 20 |
|
| 21 |
# --- MCP TOOLS ---
|
| 22 |
|
| 23 |
+
@mcp.tool()
|
| 24 |
+
def create_stripe_checkout_session(price_id: str, success_url: str, cancel_url: str) -> str:
|
| 25 |
+
"""Create a Stripe Checkout Session for a given Price ID."""
|
| 26 |
+
try:
|
| 27 |
+
session = stripe.checkout.Session.create(
|
| 28 |
+
payment_method_types=['card'],
|
| 29 |
+
line_items=[{'price': price_id, 'quantity': 1}],
|
| 30 |
+
mode='payment',
|
| 31 |
+
success_url=success_url,
|
| 32 |
+
cancel_url=cancel_url,
|
| 33 |
+
)
|
| 34 |
+
return f"Checkout Session created: {session.url}"
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error creating session: {str(e)}"
|
| 37 |
+
|
| 38 |
+
# ... (Existing tools)
|
| 39 |
+
|
| 40 |
+
# --- AGENT LOGIC ---
|
| 41 |
+
|
| 42 |
+
def aussie_router(user_input, history):
|
| 43 |
+
# ...
|
| 44 |
+
# Updated router instructions logic (should ideally be loaded from databank)
|
| 45 |
+
# Adding Stripe to the dispatch logic
|
| 46 |
+
system_instr = load_from_databank("router_instructions.md")
|
| 47 |
+
# ...
|
| 48 |
+
|
| 49 |
@mcp.tool()
|
| 50 |
def generate_ebook(title: str, author: str, chapters: list) -> str:
|
| 51 |
"""Generate EPUB and PDF files from a list of chapters (title and content)."""
|