Text-to-Image
Diffusers
English
stable-diffusion-xl
huggingface-inference-endpoints
custom-inference
Run this model with HF Jobs
Run msgxai/msgxai-hg-api on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/msgxai/msgxai-hg-api. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/msgxai/msgxai-hg-api on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use msgxai/msgxai-hg-api with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use msgxai/msgxai-hg-api with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("msgxai/msgxai-hg-api", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Prepare code for Hugging Face Inference Endpoint deployment
Browse filesFiles changed (12)
- .gitattributesDeleted-35
- .python-versionDeleted-1
- DockerfileDeleted-16
- README.md+90-48
- app.conf+4-4
- app.pyDeleted-32
- src/handler.py → handler.pyRenamed+92-22
- requirements.txt+11-9
- src/ProcfileDeleted-1
- src/app.confDeleted-11
- src/app.pyDeleted-145
- src/requirements.txtDeleted-7
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text1msgxai-hg-api12345678910111213141516# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker# you will also find guides on how best to write your Dockerfile
FROM python:3.9
RUN useradd -m -u 1000 userUSER userENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /app
COPY --chown=user ./requirements.txt requirements.txtRUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY --chown=user . /appCMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283---title: Msgxai Hugging Face Inference APIemoji: 🖼️colorFrom: yellowcolorTo: indigosdk: dockerpinned: falselicense: mitshort_description: Stable Diffusion XL image generation API---# Msgxai Hugging Face Inference APIA custom Hugging Face Inference Endpoint for Stable Diffusion XL image generation.## ConfigurationThe API is configured through the `app.conf` JSON file with the following parameters:```json{"model_id": "model-repo-id", // The Hugging Face model repository ID"name": "your-model-name", // A name for your model (optional)"prompt": "{prompt}", // Prompt template with {prompt} placeholder"negative_prompt": "...", // Default negative prompt"width": 1024, // Default image width"height": 768, // Default image height"inference_steps": 30, // Default number of inference steps"guidance_scale": 7, // Default guidance scale"use_safetensors": true, // Whether to use safetensors"clip_skip": 0 // Optional CLIP skip value (0 = disabled)}```## API Usage### Health Check```GET /```Returns: `{"status": "healthy"}`### Generate Image```POST /predict```Request Body:```json{"prompt": "your image prompt here","negative_prompt": "optional negative prompt","width": 1024,"height": 768,"inference_steps": 30,"guidance_scale": 7,"seed": 42}```Response:```json{"image_base64": "base64-encoded-image-data","seed": 42}```Note: All parameters except `prompt` are optional and will use defaults from `app.conf` if not provided.## Deployment1. Configure your `app.conf` file with desired model and parameters2. Ensure all dependencies are in `requirements.txt`3. Deploy to Hugging Face Inference Endpoints## Content FilteringThe API includes built-in filtering for child-related content in prompts.## Environment Variables- `USE_TORCH_COMPILE`: Set to "1" to enable torch compilation (default: "0")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125# Hugging Face Inference API for Stable Diffusion XLThis repository contains a text-to-image generation API designed to be deployed on Hugging Face Inference Endpoints, using Stable Diffusion XL models for image generation.## Features- Compatible with Hugging Face Inference Endpoints- Stable Diffusion XL (SDXL) model for high-quality image generation- Content filtering for safe image generation- Configurable image dimensions (default: 1024x768)- Base64-encoded image output- Performance optimizations (torch.compile, attention processors)## Project StructureThe codebase has been simplified to only use a single file:- `handler.py`: Contains the `EndpointHandler` class that implements the Hugging Face Inference Endpoints interface. This file also includes a built-in FastAPI server for local development.## ConfigurationThe service is configured via the `app.conf` JSON file with the following parameters:```json{"model_id": "your-huggingface-model-id","prompt": "template with {prompt} placeholder","negative_prompt": "default negative prompt","inference_steps": 30,"guidance_scale": 7,"use_safetensors": true,"width": 1024,"height": 768}```## API Usage### Hugging Face Inference Endpoints FormatWhen deployed to Hugging Face Inference Endpoints, the API accepts requests in the following format:```json{"inputs": "your prompt here","parameters": {"negative_prompt": "optional negative prompt","seed": 12345,"inference_steps": 30,"guidance_scale": 7,"width": 1024,"height": 768}}```Response format:```json[{"generated_image": "base64-encoded-image","seed": 12345}]```### Local Development FormatWhen running locally, you can use the same format as above, or a simplified format:```json{"prompt": "your prompt here","negative_prompt": "optional negative prompt","seed": 12345,"inference_steps": 30,"guidance_scale": 7,"width": 1024,"height": 768}```Response format from the local server:```json[{"generated_image": "base64-encoded-image","seed": 12345}]```## Deployment on Hugging Face Inference Endpoints1. Push this repository to Hugging Face Hub or your Git repository2. Create a new Inference Endpoint on Hugging Face3. Select this repository as the source4. Configure compute resources (recommended: GPU with at least 16GB VRAM)5. Deploy the endpoint### Required FilesFor deployment on Hugging Face Inference Endpoints, you need:- `handler.py` - Contains the `EndpointHandler` class implementation- `requirements.txt` - Lists the Python dependencies- `app.conf` - Contains configuration parametersNote: A `Procfile` is not needed for Hugging Face Inference Endpoints deployment, as the service automatically detects and uses the `EndpointHandler` class.## Local Development1. Install dependencies: `pip install -r requirements.txt`2. Run the API locally: `python handler.py [--port PORT] [--host HOST]`3. The API will be available at http://localhost:8000The local server uses the FastAPI implementation included in `handler.py` that provides the same functionality as the Hugging Face Inference Endpoints interface.## Environment Variables- `PORT`: Port to run the server on (default: 8000)- `USE_TORCH_COMPILE`: Set to "1" to enable torch.compile for performance (default: "0")## LicenseThis project is licensed under the terms of the MIT license.
2 unmodified lines345678910112 unmodified lines"name": "hentai-waianiv6-card","prompt": "score_9, score_8_up, score_7_up,rating_explicit,BREAK, {prompt}","negative_prompt": "source_furry, source_pony, source_cartoon,3d, blurry, incest, beastiality, children, loli, child, kids, teens, text, logo, timestamp, artist name, artist logo, watermark, web address, copyright name, copyright notice, emblem, comic, title, logo, character name, border, patreon username, signature, webpage, company name, caption, labels, comments","width": 1024,"height": 768,"inference_steps": 30,"guidance_scale": 7,"use_safetensors": true}2 unmodified lines345678910112 unmodified lines"name": "hentai-waianiv6-card","prompt": "score_9, score_8_up, score_7_up,rating_explicit,BREAK, {prompt}","negative_prompt": "source_furry, source_pony, source_cartoon,3d, blurry, incest, beastiality, children, loli, child, kids, teens, text, logo, timestamp, artist name, artist logo, watermark, web address, copyright name, copyright notice, emblem, comic, title, logo, character name, border, patreon username, signature, webpage, company name, caption, labels, comments","inference_steps": 30,"guidance_scale": 7,"use_safetensors": true,"width": 1024,"height": 768}
1234567891011121314151617181920212223242526272829303132from fastapi import FastAPI, Requestfrom src.handler import EndpointHandlerimport json
app = FastAPI()
# Initialize the handlerhandler = EndpointHandler()
@app.get("/")def greet_json(): """Simple health check endpoint.""" return {"status": "healthy"}
@app.post("/predict")async def predict(request: Request): """ Main prediction endpoint that processes image generation requests. Args: request (Request): The FastAPI request object Returns: dict: The generated image as base64 and other metadata """ # Parse the request data data = await request.json() # Process the request using our handler result = handler(data) return result52 unmodified lines5354555657581 unmodified line6061626364656667686970717249 unmodified lines1221231241251261271281291301311321331341351361376 unmodified lines1441451461471481491501511521531 unmodified line15515615715815916016116216316416516616716816917017112 unmodified lines18418518618718818919019119219319452 unmodified lines"""Custom handler for Hugging Face Inference Endpoints.This class follows the HF Inference Endpoints specification."""def __init__(self, path="", config=None):1 unmodified lineInitialize the handler with model path and configurations.Args:path (str): Path to the model. Not used for this implementation.config (dict, optional): Configuration for the handler. Not used for this implementation."""# Load configuration from app.conftry:with open("app.conf", "r") as f:self.cfg = json.load(f)except Exception as e:print(f"Error loading configuration: {e}")self.cfg = {}49 unmodified linesdef __call__(self, data):"""Process the inference request.This is called for each inference request.Args:data: The input data for the inference requestReturns:dict: The result of the inference"""# Validate that the model is loadedif not self.pipe:return {"error": "Model not loaded. Please check initialization logs."}# Parse the request payload6 unmodified linesexcept Exception as e:return {"error": f"Failed to parse request data: {str(e)}"}# Get the prompt from the payloadprompt_text = payload.get("prompt", "")if not prompt_text:return {"error": "No prompt provided"}# Apply child-content filtering to the promptif contains_child_related_content(prompt_text):1 unmodified line# Replace placeholder in the prompt template from configcombined_prompt = self.cfg.get("prompt", "{prompt}").replace("{prompt}", prompt_text)# Use negative_prompt if provided; otherwise, default to confignegative_prompt = payload.get("negative_prompt", self.cfg.get("negative_prompt", ""))# Get parameters from config or override with request paramswidth = int(payload.get("width", self.cfg.get("width", 1024)))height = int(payload.get("height", self.cfg.get("height", 768)))inference_steps = int(payload.get("inference_steps", self.cfg.get("inference_steps", 30)))guidance_scale = float(payload.get("guidance_scale", self.cfg.get("guidance_scale", 7)))# Use provided seed or generate a random oneseed = int(payload.get("seed", random.randint(0, MAX_SEED)))generator = torch.Generator(self.pipe.device).manual_seed(seed)try:12 unmodified lines# Convert the first generated image to base64img_base64 = pil_image_to_base64(outputs.images[0])# Return the responsereturn {"image_base64": img_base64, "seed": seed}except Exception as e:# Log the error and return an error responseerror_message = f"Image generation failed: {str(e)}"print(error_message)return {"error": error_message}52 unmodified lines535455565758596061621 unmodified line646566676869707172737475767778798081828349 unmodified lines1331341351361371381391401411421431441451461471481491506 unmodified lines1571581591601611621631641651661671681691701711721731741751761 unmodified line17817918018118218318418518618718818919019119219319419519612 unmodified lines20921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326452 unmodified lines"""Custom handler for Hugging Face Inference Endpoints.This class follows the HF Inference Endpoints specification.For Hugging Face Inference Endpoints, only this class is needed.It provides both the initialization (__init__) and inference (__call__) methodsrequired by the Hugging Face Inference API."""def __init__(self, path="", config=None):1 unmodified lineInitialize the handler with model path and configurations.Args:path (str): Path to the model directory (used by HF Inference Endpoints).config (dict, optional): Configuration for the handler, passed by HF Inference Endpoints."""# Load configuration from app.conf or use provided configtry:if config:# Use config provided by HF Inference Endpointsself.cfg = configelse:# Try to load from app.conf as fallbackconfig_path = os.path.join(path, "app.conf") if path else "app.conf"with open(config_path, "r") as f:self.cfg = json.load(f)print("Configuration loaded successfully")except Exception as e:print(f"Error loading configuration: {e}")self.cfg = {}49 unmodified linesdef __call__(self, data):"""Process the inference request.This is called for each inference request by the Hugging Face Inference API.Args:data: The input data for the inference requestFor HF Inference Endpoints, this is typically a dict with "inputs" fieldReturns:list: A list containing the generated image as base64 string and seedThis follows the HF Inference Endpoints output format"""# Validate that the model is loadedif not hasattr(self, 'pipe') or self.pipe is None:return {"error": "Model not loaded. Please check initialization logs."}# Parse the request payload6 unmodified linesexcept Exception as e:return {"error": f"Failed to parse request data: {str(e)}"}# Extract parameters from the payloadparameters = {}if "parameters" in payload and isinstance(payload["parameters"], dict):# HF Inference Endpoints format: {"inputs": "prompt", "parameters": {...}}parameters = payload["parameters"]# Get the prompt from the payloadprompt_text = payload.get("inputs", "")if not prompt_text:# Try to get prompt from different fields for compatibilityprompt_text = payload.get("prompt", "")if not prompt_text:return {"error": "No prompt provided. Please include 'inputs' or 'prompt' field."}# Apply child-content filtering to the promptif contains_child_related_content(prompt_text):1 unmodified line# Replace placeholder in the prompt template from configcombined_prompt = self.cfg.get("prompt", "{prompt}").replace("{prompt}", prompt_text)# Use negative_prompt from parameters or payload, fall back to confignegative_prompt = parameters.get("negative_prompt", payload.get("negative_prompt", self.cfg.get("negative_prompt", "")))# Get dimensions from config (default to 1024x768 if not specified)width = int(self.cfg.get("width", 1024))height = int(self.cfg.get("height", 768))# Other generation parametersinference_steps = int(parameters.get("inference_steps", payload.get("inference_steps", self.cfg.get("inference_steps", 30))))guidance_scale = float(parameters.get("guidance_scale", payload.get("guidance_scale", self.cfg.get("guidance_scale", 7))))# Use provided seed or generate a random oneseed = int(parameters.get("seed", payload.get("seed", random.randint(0, MAX_SEED))))generator = torch.Generator(self.pipe.device).manual_seed(seed)try:12 unmodified lines# Convert the first generated image to base64img_base64 = pil_image_to_base64(outputs.images[0])# Return the response formatted for Hugging Face Inference Endpointsreturn [{"generated_image": img_base64, "seed": seed}]except Exception as e:# Log the error and return an error responseerror_message = f"Image generation failed: {str(e)}"print(error_message)return {"error": error_message}# For local testing without HF Inference Endpointsif __name__ == "__main__":import argparseimport uvicornfrom fastapi import FastAPI, Requestfrom fastapi.responses import JSONResponse# Parse command-line argumentsparser = argparse.ArgumentParser(description="Run the text-to-image API locally")parser.add_argument("--port", type=int, default=8000, help="Port to run the server on")parser.add_argument("--host", type=str, default="0.0.0.0", help="Host to run the server on")args = parser.parse_args()# Create FastAPI appapp = FastAPI(title="Text-to-Image API with Content Filtering")# Initialize the handlerhandler = EndpointHandler()@app.get("/")async def read_root():"""Health check endpoint."""return {"status": "ok", "message": "Text-to-Image API is running"}@app.post("/")async def generate_image(request: Request):"""Main inference endpoint."""try:body = await request.json()result = handler(body)if "error" in result:return JSONResponse(status_code=500, content={"error": result["error"]})return resultexcept Exception as e:return JSONResponse(status_code=500,content={"error": f"Failed to process request: {str(e)}"})# Run the serverprint(f"Starting server on http://{args.host}:{args.port}")uvicorn.run(app, host=args.host, port=args.port)
123456789fastapiuvicorn[standard]diffuserstransformerstorchacceleratehuggingface_hubpillowsafetensors1234567891011fastapi>=0.95.0uvicorn>=0.22.0torch>=2.0.0diffusers>=0.19.0transformers>=4.30.0accelerate>=0.20.0huggingface_hub>=0.16.0pydantic>=1.10.0Pillow>=9.0.0scipy>=1.10.0safetensors>=0.3.0
1web: uvicorn app:app --host 0.0.0.0 --port $PORT1234567891011{ "model_id": "John6666/wai-ani-hentai-pony-v3-sdxl", "name": "hentai-waianiv6-card", "prompt": "score_9, score_8_up, score_7_up,rating_explicit,BREAK, {prompt}", "negative_prompt": "source_furry, source_pony, source_cartoon,3d, blurry, incest, beastiality, children, loli, child, kids, teens, text, logo, timestamp, artist name, artist logo, watermark, web address, copyright name, copyright notice, emblem, comic, title, logo, character name, border, patreon username, signature, webpage, company name, caption, labels, comments", "width": 1024, "height": 768, "inference_steps": 30, "guidance_scale": 7, "use_safetensors": true}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145import osimport jsonimport randomimport reimport base64from io import BytesIO
from fastapi import FastAPI, HTTPExceptionfrom pydantic import BaseModelfrom PIL import Image
import torchfrom huggingface_hub import snapshot_downloadfrom diffusers import ( AutoencoderKL, StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler, DPMSolverSDEScheduler)from diffusers.models.attention_processor import AttnProcessor2_0
# Global constantsMAX_SEED = 12211231NUM_IMAGES_PER_PROMPT = 1USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
# Load configuration from app.confwith open("app.conf", "r") as f: cfg = json.load(f)
# --- Child-Content Filtering Functions ---child_related_regex = re.compile( r'(child|children|kid|kids|baby|babies|toddler|infant|juvenile|minor|underage|preteen|adolescent|youngster|youth|son|daughter|young|kindergarten|preschool|' r'([1-9]|1[0-7])[\s_\-|\.\,]*year(s)?[\s_\-|\.\,]*old|' r'little|small|tiny|short|young|new[\s_\-|\.\,]*born[\s_\-|\.\,]*(boy|girl|male|man|bro|brother|sis|sister))', re.IGNORECASE)
def remove_child_related_content(prompt: str) -> str: """Remove any child-related references from the prompt.""" cleaned_prompt = re.sub(child_related_regex, '', prompt) return cleaned_prompt.strip()
def contains_child_related_content(prompt: str) -> bool: """Check if the prompt contains child-related content.""" return bool(child_related_regex.search(prompt))
# --- Model Pipeline Loading ---def load_pipeline_and_scheduler(): clip_skip = cfg.get("clip_skip", 0) # Download model files from Hugging Face Hub ckpt_dir = snapshot_download(repo_id=cfg["model_id"]) # Load the VAE model (for decoding latents) vae = AutoencoderKL.from_pretrained(os.path.join(ckpt_dir, "vae"), torch_dtype=torch.float16) # Load the Stable Diffusion XL pipeline pipe = StableDiffusionXLPipeline.from_pretrained( ckpt_dir, vae=vae, torch_dtype=torch.float16, use_safetensors=cfg.get("use_safetensors", True), variant="fp16" ) pipe = pipe.to("cuda") pipe.unet.set_attn_processor(AttnProcessor2_0()) # Set up samplers/schedulers based on configuration samplers = { "Euler a": EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config), "DPM++ SDE Karras": DPMSolverSDEScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True) } # Default to "DPM++ SDE Karras" if not specified pipe.scheduler = samplers.get(cfg.get("sampler", "DPM++ SDE Karras")) # Adjust the text encoder layers if needed using clip_skip pipe.text_encoder.config.num_hidden_layers -= (clip_skip - 1) if USE_TORCH_COMPILE: pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True) print("Model Compiled!") return pipe
# Load the model pipeline once at startuppipe = load_pipeline_and_scheduler()
# --- Utility Function: Convert PIL Image to Base64 ---def pil_image_to_base64(img: Image.Image) -> str: buffered = BytesIO() img.convert("RGB").save(buffered, format="WEBP", quality=90) return base64.b64encode(buffered.getvalue()).decode("utf-8")
# --- FastAPI Application Setup ---app = FastAPI(title="Text-to-Image API with Content Filtering")
class GenerateRequest(BaseModel): prompt: str
@app.get("/")async def read_root(): return {"message": "Text-to-Image API with content filtering is running."}
@app.post("/generate")async def generate(req: GenerateRequest): # Apply child-content filtering to the prompt prompt_text = req.prompt if contains_child_related_content(prompt_text): prompt_text = remove_child_related_content(prompt_text) # Replace placeholder in the prompt template from config combined_prompt = cfg.get("prompt", "{prompt}").replace("{prompt}", prompt_text) # Use negative_prompt if provided; otherwise, default to empty string negative_prompt = cfg.get("negative_prompt", "") width = cfg.get("width", 1024) height = cfg.get("height", 768) inference_steps = cfg.get("inference_steps", 30) guidance_scale = cfg.get("guidance_scale", 7) # Randomize the seed for generation seed = random.randint(0, MAX_SEED) generator = torch.Generator(pipe.device).manual_seed(seed) try: outputs = pipe( prompt=combined_prompt, negative_prompt=negative_prompt, width=width, height=height, guidance_scale=guidance_scale, num_inference_steps=inference_steps, generator=generator, num_images_per_prompt=NUM_IMAGES_PER_PROMPT, output_type="pil" ) # Convert the first generated image to base64 img_base64 = pil_image_to_base64(outputs.images[0]) except Exception as e: raise HTTPException(status_code=500, detail=f"Image generation failed: {e}") return {"image_base64": img_base64, "seed": seed}
if __name__ == "__main__": import uvicorn uvicorn.run("app:app", host="0.0.0.0", port=8000)1234567fastapiuvicorntorchdiffusershuggingface_hubpydanticPillow.gitattributesDeleted-35
.python-versionDeleted-1
DockerfileDeleted-16
README.md+90-48
app.conf+4-4
app.pyDeleted-32
src/handler.py → handler.pyRenamed+92-22
requirements.txt+11-9
src/ProcfileDeleted-1
src/app.confDeleted-11
src/app.pyDeleted-145
src/requirements.txtDeleted-7