Spaces:
Runtime error
Runtime error
Upload page4.py
Browse files
page4.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
import random
|
6 |
+
from PIL import Image
|
7 |
+
from io import BytesIO
|
8 |
+
import io
|
9 |
+
|
10 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
11 |
+
|
12 |
+
def query_model(text_input):
|
13 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
14 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
15 |
+
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"}
|
16 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
+
return response.content
|
18 |
+
|
19 |
+
def sdxl():
|
20 |
+
st.write("ForgeImage")
|
21 |
+
text_input = st.text_input("Enter your prompt:", "Astronaut riding a horse")
|
22 |
+
|
23 |
+
if st.button("Create"):
|
24 |
+
image_bytes = query_model(text_input)
|
25 |
+
generated_image = Image.open(io.BytesIO(image_bytes))
|
26 |
+
|
27 |
+
st.image(generated_image, use_column_width=True)
|