File size: 819 Bytes
8a6fc44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()