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
chore: fix metadata propertoes for HF Inference Endpoint
Browse filesFiles changed (4)
- README.md+61-2
- api-inference/config.jsonAdded+5
- model-index.jsonAdded+18
- test_endpoint.pyAdded+134
6 unmodified lines789101112116 unmodified lines12913013113213313413513613713864 unmodified lines2032042052066 unmodified lines- text-to-image- diffusers- huggingface-inference-endpointspipeline_tag: text-to-imageinference: true---116 unmodified lines3. Click "Create a new endpoint"4. Configure your endpoint with the following settings:- Name: Give your endpoint a name- Instance Type: Choose a GPU instance (recommended: at least 16GB VRAM for SDXL)- Replicas: Start with 1 replica- Autoscaling: Configure as needed5. Click "Create endpoint"The Hugging Face Inference Endpoints service will automatically detect and use your `EndpointHandler` class in the `handler.py` file.64 unmodified lines## LicenseThis project is licensed under the terms of the MIT license.6 unmodified lines78910111213116 unmodified lines13013113213313413513613713813914014114214314414514614714814964 unmodified lines2142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642656 unmodified lines- text-to-image- diffusers- huggingface-inference-endpoints- custom-inferencepipeline_tag: text-to-imageinference: true---116 unmodified lines3. Click "Create a new endpoint"4. Configure your endpoint with the following settings:- Name: Give your endpoint a name- Region: Choose a region close to your users (e.g., us-east-1)- Instance Type: Choose a GPU instance (recommended: at least 16GB VRAM for SDXL)- Replicas: Start with 1 replica- Autoscaling: Configure as needed**IMPORTANT: IF YOU SEE THIS WARNING**:> "Warning: deploying this model will probably fail because the model's Diffusers pipeline is not set"5. Click "Continue anyway" - this is expected because you're using a custom handler implementation6. Under Advanced configuration:- Make sure "Framework" is set to "Custom"- Configure "Task" as "Text-to-Image"7. Click "Create endpoint"The Hugging Face Inference Endpoints service will automatically detect and use your `EndpointHandler` class in the `handler.py` file.64 unmodified lines## LicenseThis project is licensed under the terms of the MIT license.## Testing Your Inference EndpointWe've included a test script `test_endpoint.py` to help you test your deployed endpoint.### Prerequisites- Python 3.7+- Your Hugging Face API token- An active Hugging Face Inference Endpoint### Installation```bashpip install requests pillow```### Usage```bashpython test_endpoint.py --token "YOUR_HF_API_TOKEN" --url "YOUR_ENDPOINT_URL" --prompt "your test prompt here"```#### Additional Options```--negative_prompt TEXT Negative prompt to guide generation--seed INTEGER Random seed for reproducibility--steps INTEGER Number of inference steps (default: 30)--guidance FLOAT Guidance scale (default: 7.0)--width INTEGER Image width (default: 1024)--height INTEGER Image height (default: 768)--output_dir TEXT Directory to save generated images (default: "generated_images")```#### Example```bashpython test_endpoint.py \--token "hf_..." \--url "https://api-inference.huggingface.co/models/username/your-repo-name" \--prompt "beautiful sunset over mountains" \--negative_prompt "blurry, low quality" \--seed 42 \--steps 30 \--guidance 7.5```This will:1. Send a request to your endpoint2. Download the generated image3. Save it to the specified output directory4. Display the seed used for generation
12345{ "framework": "custom", "task": "text-to-image", "custom_handler": "handler:EndpointHandler"} 123456789101112131415161718{ "_class_name": "CustomInferenceAPI", "task": "text-to-image", "widget": { "input_template": { "inputs": "beautiful landscape with mountains", "parameters": { "negative_prompt": "blurry, low quality", "seed": 42, "inference_steps": 30, "guidance_scale": 7, "width": 1024, "height": 768 } }, "output_widget": "Base64ImageOutput" }} 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134#!/usr/bin/env python3# This script demonstrates how to test your Hugging Face Inference Endpoint# Replace the API_TOKEN and API_URL with your actual values
import requestsimport jsonimport base64from PIL import Imageimport ioimport argparseimport os
def test_inference_endpoint(api_token, api_url, prompt, negative_prompt=None, seed=None, inference_steps=30, guidance_scale=7, width=1024, height=768, output_dir="generated_images"): """ Test a Hugging Face Inference Endpoint for image generation. Args: api_token (str): Your Hugging Face API token api_url (str): The URL of your inference endpoint prompt (str): The text prompt for image generation negative_prompt (str, optional): Negative prompt to guide generation seed (int, optional): Random seed for reproducibility inference_steps (int): Number of inference steps guidance_scale (float): Guidance scale for generation width (int): Image width height (int): Image height output_dir (str): Directory to save generated images """ # Create output directory if it doesn't exist os.makedirs(output_dir, exist_ok=True) # Headers for the request headers = { "Authorization": f"Bearer {api_token}", "Content-Type": "application/json" } # Build parameters dictionary with provided values parameters = { "width": width, "height": height, "inference_steps": inference_steps, "guidance_scale": guidance_scale } # Add optional parameters if provided if negative_prompt: parameters["negative_prompt"] = negative_prompt if seed: parameters["seed"] = seed # Request payload payload = { "inputs": prompt, "parameters": parameters } print(f"Sending request to {api_url}...") print(f"Prompt: '{prompt}'") try: # Send the request response = requests.post(api_url, headers=headers, json=payload) # Check for errors if response.status_code != 200: print(f"Error: {response.status_code} - {response.text}") return # Parse the response result = response.json() # Check for error in the response if isinstance(result, dict) and "error" in result: print(f"API Error: {result['error']}") return # Extract the generated image and seed if isinstance(result, list) and len(result) > 0: item = result[0] if "generated_image" in item: # Convert the base64-encoded image to a PIL Image image_bytes = base64.b64decode(item["generated_image"]) image = Image.open(io.BytesIO(image_bytes)) # Create a filename based on the prompt and seed used_seed = item.get("seed", "unknown_seed") filename = f"{output_dir}/generated_{used_seed}.png" # Save the image image.save(filename) print(f"Image saved to {filename}") print(f"Seed: {used_seed}") return image else: print("Response doesn't contain 'generated_image' field") else: print("Unexpected response format:", result) except Exception as e: print(f"Error: {str(e)}")
if __name__ == "__main__": # Parse command line arguments parser = argparse.ArgumentParser(description="Test Hugging Face Inference Endpoints for image generation") parser.add_argument("--token", required=True, help="Your Hugging Face API token") parser.add_argument("--url", required=True, help="URL of your inference endpoint") parser.add_argument("--prompt", required=True, help="Text prompt for image generation") parser.add_argument("--negative_prompt", help="Negative prompt") parser.add_argument("--seed", type=int, help="Random seed for reproducibility") parser.add_argument("--steps", type=int, default=30, help="Number of inference steps") parser.add_argument("--guidance", type=float, default=7, help="Guidance scale") parser.add_argument("--width", type=int, default=1024, help="Image width") parser.add_argument("--height", type=int, default=768, help="Image height") parser.add_argument("--output_dir", default="generated_images", help="Directory to save generated images") args = parser.parse_args() # Call the test function with provided arguments test_inference_endpoint( api_token=args.token, api_url=args.url, prompt=args.prompt, negative_prompt=args.negative_prompt, seed=args.seed, inference_steps=args.steps, guidance_scale=args.guidance, width=args.width, height=args.height, output_dir=args.output_dir ) README.md+61-2
api-inference/config.jsonAdded+5
model-index.jsonAdded+18
test_endpoint.pyAdded+134