svjack commited on
Commit
4abec4b
1 Parent(s): bb6155a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -4,7 +4,14 @@ import io
4
  import random
5
  import os
6
  from PIL import Image
 
7
 
 
 
 
 
 
 
8
  list_models = [
9
  "SDXL-1.0",
10
  "SD-1.5",
@@ -15,10 +22,12 @@ list_models = [
15
  "Dalle-3-XL",
16
  "Midjourney-V4-XL",
17
  ]
 
18
 
19
  def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7,
20
- seed=None):
21
 
 
22
  if current_model == "SD-1.5":
23
  API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
24
  elif current_model == "SDXL-1.0":
@@ -34,11 +43,14 @@ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None
34
  elif current_model == "Dalle-3-XL":
35
  API_URL = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
36
  elif current_model == "Midjourney-V4-XL":
37
- API_URL = "https://api-inference.huggingface.co/models/openskyml/midjourney-v4-xl"
 
38
 
39
  API_TOKEN = os.environ.get("HF_READ_TOKEN")
40
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
41
 
 
 
42
 
43
  if image_style == "None style":
44
  payload = {
@@ -73,9 +85,13 @@ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None
73
  "seed": seed if seed is not None else random.randint(-1, 2147483647)
74
  }
75
 
76
- image_bytes = requests.post(API_URL, headers=headers, json=payload).content
 
 
 
77
  image = Image.open(io.BytesIO(image_bytes))
78
  return image
 
79
 
80
 
81
  css = """
 
4
  import random
5
  import os
6
  from PIL import Image
7
+ from huggingface_hub import InferenceApi, InferenceClient
8
 
9
+ client = InferenceClient()
10
+
11
+ models = client.list_deployed_models()
12
+ list_models = models["text-to-image"]
13
+
14
+ '''
15
  list_models = [
16
  "SDXL-1.0",
17
  "SD-1.5",
 
22
  "Dalle-3-XL",
23
  "Midjourney-V4-XL",
24
  ]
25
+ '''
26
 
27
  def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7,
28
+ seed=None, api_dict = api_dict):
29
 
30
+ '''
31
  if current_model == "SD-1.5":
32
  API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
33
  elif current_model == "SDXL-1.0":
 
43
  elif current_model == "Dalle-3-XL":
44
  API_URL = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
45
  elif current_model == "Midjourney-V4-XL":
46
+ API_URL = "https://api-inference.huggingface.co/models/openskyml/midjourney-v4-xl"
47
+ '''
48
 
49
  API_TOKEN = os.environ.get("HF_READ_TOKEN")
50
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
51
 
52
+ api = InferenceApi(current_model)
53
+ api.headers = headers
54
 
55
  if image_style == "None style":
56
  payload = {
 
85
  "seed": seed if seed is not None else random.randint(-1, 2147483647)
86
  }
87
 
88
+ #image_bytes = requests.post(API_URL, headers=headers, json=payload).content
89
+ image = model_api(data = payload)
90
+ return image
91
+ '''
92
  image = Image.open(io.BytesIO(image_bytes))
93
  return image
94
+ '''
95
 
96
 
97
  css = """