Run this model with HF Jobs
Run Paresh1879/stable-diffusion-xl-thumbsup-extend 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/Paresh1879/stable-diffusion-xl-thumbsup-extend. 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/Paresh1879/stable-diffusion-xl-thumbsup-extend 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 Paresh1879/stable-diffusion-xl-thumbsup-extend with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Paresh1879/stable-diffusion-xl-thumbsup-extend with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("Paresh1879/stable-diffusion-xl-thumbsup-extend", 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
Download SDXL_API_Server.py from Paresh1879/stable-diffusion-xl-thumbsup-extend: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/Paresh1879/stable-diffusion-xl-thumbsup-extend/resolve/main/SDXL_API_Server.py
- Command line
-
hf download hf://Paresh1879/stable-diffusion-xl-thumbsup-extend/SDXL_API_Server.py
-
curl -L -o SDXL_API_Server.py https://huggingface.co/Paresh1879/stable-diffusion-xl-thumbsup-extend/resolve/main/SDXL_API_Server.py
2.57 kB
| import requests | |
| import io | |
| import logging | |
| from PIL import Image | |
| from flask import Flask, request, jsonify, send_file | |
| from functools import wraps | |
| from requests.adapters import HTTPAdapter | |
| from requests.packages.urllib3.util.retry import Retry | |
| API_URL = "https://api-inference.huggingface.co/models/Paresh1879/stable-diffusion-xl-thumbsup-extend" | |
| API_KEY = "your-api-key" | |
| app = Flask(__name__) | |
| # Storage for API key usage counts | |
| api_key_usage = {} | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| # Configure HTTP Session with Retry Logic | |
| session = requests.Session() | |
| retry = Retry( | |
| total=10, | |
| backoff_factor=2, | |
| status_forcelist=[429, 500, 502, 503, 504], | |
| allowed_methods=["HEAD", "GET", "OPTIONS", "POST"] | |
| ) | |
| adapter = HTTPAdapter(max_retries=retry) | |
| session.mount("http://", adapter) | |
| session.mount("https://", adapter) | |
| def query(payload): | |
| try: | |
| response = session.post(API_URL, headers={"Authorization": f"Bearer {API_KEY}"}, json=payload) | |
| response.raise_for_status() | |
| return response.content | |
| except requests.exceptions.RequestException as e: | |
| logger.error(f"Request failed: {e}") | |
| raise | |
| # checking api_key | |
| def require_api_key(f): | |
| def check_api_key(*args, **kwargs): | |
| api_key = request.headers.get('Authorization') | |
| if api_key != f"Bearer {API_KEY}": | |
| return jsonify({"error": "Unauthorized"}), 401 | |
| if api_key not in api_key_usage: | |
| api_key_usage[api_key] = 0 | |
| api_key_usage[api_key] += 1 | |
| return f(*args, **kwargs) | |
| return check_api_key | |
| # /generate_image endpoint | |
| def generate_image(): | |
| prompt = request.json.get('prompt') | |
| if not prompt: | |
| return jsonify({"error": "Missing prompt"}), 400 | |
| try: | |
| image_bytes = query({"inputs": prompt}) | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| img_io = io.BytesIO() | |
| image.save(img_io, 'PNG') | |
| img_io.seek(0) | |
| return send_file(img_io, mimetype='image/png') | |
| except requests.exceptions.RequestException as e: | |
| return jsonify({"error": "Service is temporarily unavailable. Please try again later."}), 503 | |
| # api_key_usage endpoint | |
| def get_api_key_usage(): | |
| api_key = request.headers.get('Authorization') | |
| usage_count = api_key_usage.get(api_key, 0) | |
| return jsonify({"usage_count": usage_count}) | |
| if __name__ == '__main__': | |
| app.run(debug=True) | |