mcp / app_ld..py
inoculatemedia's picture
Rename app.py to app_ld..py
326b7a2 verified
from mcp.server.fastmcp import FastMCP
from gradio_client import Client
import sys
import io
import json
import gradio as gr
from huggingface_hub import InferenceClient
mcp = FastMCP("gradio-spaces")
clients = {}
def get_client(space_id: str) -> Client:
"""Get or create a Gradio client for the specified space."""
if space_id not in clients:
clients[space_id] = Client(space_id)
return clients[space_id]
@mcp.tool()
async def generate_image(prompt: str, space_id: str = "inoculatemedia/SanaSprint") -> str:
"""Generate an image using Flux.
Args:
prompt: Text prompt describing the image to generate
space_id: inoculatemedia/FramePack-F1
"""
client = get_client(space_id)
result = client.predict(
prompt=prompt,
model_size="1.6B",
seed=0,
randomize_seed=True,
width=1024,
height=1024,
guidance_scale=4.5,
num_inference_steps=2,
api_name="/infer"
)
return result