Spaces:
Runtime error
Runtime error
import os | |
import gradio as gr | |
import requests | |
from PIL import Image | |
import io | |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" | |
api_key = os.getenv("API_KEY") | |
def query(payload): | |
headers = {"Authorization": f"Bearer {api_key}"} | |
response = requests.post(API_URL, headers=headers, json=payload) | |
return response.content | |
def image_generation(prompt): | |
input_prompt = { | |
"inputs": prompt, | |
} | |
image_bytes = query(input_prompt) | |
image = Image.open(io.BytesIO(image_bytes)) | |
return image | |
title = "Stable Fiddusion XL" | |
description = "This app generates an image based on the provided prompt using the Stable Diffusion XL model." | |
gr.Interface(fn=image_generation, inputs="text", outputs="image", title=title, description=description).launch() |