ehristoforu commited on
Commit
e31d96d
·
verified ·
1 Parent(s): 6f0759b

Update page4.py

Browse files
Files changed (1) hide show
  1. page4.py +19 -6
page4.py CHANGED
@@ -10,18 +10,31 @@ import io
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)
 
 
 
 
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 = {
16
+ "inputs": text_input,
17
+ "num_inference_steps": 18,
18
+ "guidance_scale": 4,
19
+ "seed": random.randint(1, 9999999),
20
+ "width": 1024,
21
+ "height": 1024,
22
+ "negative_prompt": "blurry, ugly, deformed, bad anatomy"
23
+ }
24
+ response = requests.post(API_URL, headers=headers, json=payload)
25
+ return response.content
26
 
27
  def sdxl():
28
  st.write("ForgeImage")
29
  text_input = st.text_input("Enter your prompt:", "Astronaut riding a horse")
30
 
31
+ generated_image = None # Инициализация переменной
32
+
33
  if st.button("Create"):
34
  image_bytes = query_model(text_input)
35
  generated_image = Image.open(io.BytesIO(image_bytes))
36
 
37
+ if generated_image is not None: # Проверка, что переменная существует
38
+ st.image(generated_image, use_column_width=True)
39
+
40
+ sdxl()