Spaces:
Runtime error
Runtime error
| # -*- coding: utf-8 -*- | |
| """S-D-XL-pipeline.ipynb | |
| Automatically generated by Colaboratory. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1iDFfGVa5XpZSZ1yzv-HeFpiB763xt67D | |
| """ | |
| import requests | |
| import gradio as gr | |
| from PIL import Image | |
| import io | |
| from transformers import utils | |
| utils.move_cache() | |
| import os | |
| hf_token = os.getenv('HF_TOKEN') | |
| API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" | |
| headers = {"Authorization": f"Bearer {hf_token}"} | |
| def query(payload): | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| return response.content | |
| def generate_image(prompt): | |
| image_bytes = query({"inputs": prompt}) | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| return image | |
| iface = gr.Interface( | |
| fn=generate_image, | |
| inputs="text", | |
| outputs="image", | |
| title="Stable-Diffusion-XL for high quality image generation" | |
| ) | |
| iface.launch() | |