zenafey commited on
Commit
501d9eb
1 Parent(s): 9dc331c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -10,9 +10,10 @@ from io import BytesIO
10
 
11
  class Prodia:
12
  def __init__(self, api_key, base=None):
13
- self.base = base or "https://api.prodia.com/v1"
14
  self.headers = {
15
  "X-Prodia-Key": api_key
 
16
  }
17
 
18
  def generate(self, params):
@@ -40,6 +41,12 @@ class Prodia:
40
  response = self._get(f"{self.base}/sdxl/samplers")
41
  return response.json()
42
 
 
 
 
 
 
 
43
  def _post(self, url, params):
44
  headers = {
45
  **self.headers,
@@ -60,6 +67,8 @@ class Prodia:
60
 
61
  return response
62
 
 
 
63
 
64
  def image_to_base64(image_path):
65
  # Open the image with PIL
@@ -78,16 +87,24 @@ def image_to_base64(image_path):
78
  prodia_client = Prodia(api_key=os.getenv("PRODIA_API_KEY"))
79
 
80
  def flip_text(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
81
- result = prodia_client.generate({
 
82
  "prompt": prompt,
83
  "negative_prompt": negative_prompt,
84
- "model": model,
85
  "steps": steps,
86
- "sampler": sampler,
87
  "cfg_scale": cfg_scale,
88
  "width": width,
89
  "height": height,
90
  "seed": seed
 
 
 
 
 
 
 
 
 
91
  })
92
 
93
  job = prodia_client.wait(result)
 
10
 
11
  class Prodia:
12
  def __init__(self, api_key, base=None):
13
+ self.base = base or "https://api.prodia.com/v2"
14
  self.headers = {
15
  "X-Prodia-Key": api_key
16
+ "Authorization": f"Bearer {os.getenv("API_KEY")}"
17
  }
18
 
19
  def generate(self, params):
 
41
  response = self._get(f"{self.base}/sdxl/samplers")
42
  return response.json()
43
 
44
+
45
+ def generate_v2(self, config):
46
+ response = self._post("https://inference.prodia.com/v2/job", {"type": "v2.job.sdxl.txt2img", "config": config})
47
+ return Image.open(BytesIO(r.content)).convert("RGBA")
48
+
49
+
50
  def _post(self, url, params):
51
  headers = {
52
  **self.headers,
 
67
 
68
  return response
69
 
70
+
71
+
72
 
73
  def image_to_base64(image_path):
74
  # Open the image with PIL
 
87
  prodia_client = Prodia(api_key=os.getenv("PRODIA_API_KEY"))
88
 
89
  def flip_text(prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed):
90
+
91
+ config_without_model_and_sampler = {
92
  "prompt": prompt,
93
  "negative_prompt": negative_prompt,
 
94
  "steps": steps,
 
95
  "cfg_scale": cfg_scale,
96
  "width": width,
97
  "height": height,
98
  "seed": seed
99
+ }
100
+
101
+ if model == "sd_xl_base_1.0.safetensors [be9edd61]":
102
+ return prodia_client.generate_v2(config_without_model_and_sampler)
103
+
104
+ result = prodia_client.generate({
105
+ **config_without_model_and_sampler
106
+ "model": model,
107
+ "sampler": sampler
108
  })
109
 
110
  job = prodia_client.wait(result)