File size: 951 Bytes
3a478bb
 
 
 
 
 
 
4aa5c57
3a478bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
import requests
import gradio as gr
import io
from PIL import Image
import hashlib

API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
headers = {"Authorization": {HG} }

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.content

def generate_image(prompt):
    # Add a unique identifier to the prompt
    prompt_with_identifier = prompt + str(hashlib.md5(prompt.encode()).hexdigest())
    image_bytes = query({
        "inputs": prompt_with_identifier,
    })
    image = Image.open(io.BytesIO(image_bytes))
    return image

iface = gr.Interface(generate_image, 
                     inputs="text", 
                     outputs="image", 
                     title="Generate Image from Text",
                     description="Enter a text prompt to generate a new image each time.",
                     allow_flagging=False)

iface.launch()