File size: 991 Bytes
6f0759b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import time
import os
import random
from PIL import Image
from io import BytesIO
import io

HF_TOKEN = os.getenv("HF_TOKEN")

def query_model(text_input):
        API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
        headers = {"Authorization": f"Bearer {HF_TOKEN}"}
        payload = {"inputs": text_input, "num_inference_steps": 18, "guidance_scale": 4, "seed": random.randint(1, 9999999), "width": 1024, "height": 1024, "negative_prompt": "blurry, ugly, deformed, bad anatomy"}
        response = requests.post(API_URL, headers=headers, json=payload)
        return response.content

def sdxl():
    st.write("ForgeImage")
    text_input = st.text_input("Enter your prompt:", "Astronaut riding a horse")

    if st.button("Create"):   
        image_bytes = query_model(text_input)
        generated_image = Image.open(io.BytesIO(image_bytes))

    st.image(generated_image, use_column_width=True)