EmoCube commited on
Commit
5398e17
·
verified ·
1 Parent(s): 014e444

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -5,17 +5,19 @@ import random
5
  import os
6
  import time
7
  from PIL import Image
8
- from deep_translator import GoogleTranslator
9
  import json
10
 
11
  # Project by Nymbo
12
 
13
- API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
 
 
 
14
  API_TOKEN = os.getenv("HF_READ_TOKEN")
15
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
16
  timeout = 100
17
 
18
- def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
19
  if prompt == "" or prompt == None:
20
  return None
21
 
@@ -29,12 +31,13 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
29
  "is_negative": is_negative,
30
  "steps": steps,
31
  "cfg_scale": cfg_scale,
32
- "seed": seed if seed != -1 else random.randint(1, 1000000000),
33
  "strength": strength
34
  }
35
 
 
36
  response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
37
- if response.status_code != 200:
38
  print(f"Error: Failed to get image. Response status: {response.status_code}")
39
  print(f"Response content: {response.text}")
40
  if response.status_code == 503:
@@ -59,7 +62,7 @@ css = """
59
  """
60
 
61
  with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
62
- gr.HTML("<center><h1>Stable Diffusion XL</h1></center>")
63
  with gr.Column(elem_id="app-container"):
64
  with gr.Row():
65
  with gr.Column(elem_id="prompt-container"):
@@ -73,12 +76,11 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
73
  method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
74
  strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
75
  seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
 
76
 
77
  with gr.Row():
78
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
79
  with gr.Row():
80
  image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
81
 
82
- text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
83
-
84
- app.launch(show_api=False, share=False)
 
5
  import os
6
  import time
7
  from PIL import Image
 
8
  import json
9
 
10
  # Project by Nymbo
11
 
12
+ API_URLS = {
13
+ "SDXL 1.0": "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0",
14
+ "SD 3.5": "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large"
15
+ }
16
  API_TOKEN = os.getenv("HF_READ_TOKEN")
17
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
18
  timeout = 100
19
 
20
+ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, model="SDXL 1.0"):
21
  if prompt == "" or prompt == None:
22
  return None
23
 
 
31
  "is_negative": is_negative,
32
  "steps": steps,
33
  "cfg_scale": cfg_scale,
34
+ "seed": seed if seed!= -1 else random.randint(1, 1000000000),
35
  "strength": strength
36
  }
37
 
38
+ API_URL = API_URLS[model]
39
  response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
40
+ if response.status_code!= 200:
41
  print(f"Error: Failed to get image. Response status: {response.status_code}")
42
  print(f"Response content: {response.text}")
43
  if response.status_code == 503:
 
62
  """
63
 
64
  with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
65
+ gr.HTML("<center><h1>Stable Diffusion</h1></center>")
66
  with gr.Column(elem_id="app-container"):
67
  with gr.Row():
68
  with gr.Column(elem_id="prompt-container"):
 
76
  method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
77
  strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
78
  seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
79
+ model = gr.Radio(label="Model", value="SDXL 1.0", choices=["SDXL 1.0", "SD 3.5"])
80
 
81
  with gr.Row():
82
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
83
  with gr.Row():
84
  image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
85
 
86
+ text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed,