clone3 commited on
Commit
8229074
1 Parent(s): 22fd0f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -3
app.py CHANGED
@@ -1,6 +1,10 @@
1
  #!/usr/bin/env python
2
  from __future__ import annotations
3
 
 
 
 
 
4
  import os
5
  import random
6
  import time
@@ -55,6 +59,21 @@ pipe.vae_decoder = CustomOVModelVaeDecoder(model = OVBaseModel.load_model(f"{tae
55
  pipe.reshape(batch_size=batch_size, height=height, width=width, num_images_per_prompt=num_images)
56
  pipe.compile()
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
59
  if randomize_seed:
60
  seed = random.randint(0, MAX_SEED)
@@ -73,6 +92,7 @@ def save_images(image_array, profile: gr.OAuthProfile | None, metadata: dict):
73
 
74
  def generate(
75
  prompt: str,
 
76
  seed: int = 0,
77
  guidance_scale: float = 8.0,
78
  num_inference_steps: int = 4,
@@ -88,6 +108,7 @@ def generate(
88
  seed = randomize_seed_fn(seed, randomize_seed)
89
  np.random.seed(seed)
90
  start_time = time.time()
 
91
  result = pipe(
92
  prompt=prompt,
93
  width=width,
@@ -99,7 +120,7 @@ def generate(
99
  ).images
100
  paths = save_images(result, profile, metadata={"prompt": prompt, "seed": seed, "width": width, "height": height, "guidance_scale": guidance_scale, "num_inference_steps": num_inference_steps})
101
  print(time.time() - start_time)
102
- return paths, seed
103
 
104
  examples = [
105
  "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography",
@@ -115,6 +136,7 @@ with gr.Blocks(css="style.css") as demo:
115
  elem_id="duplicate-button",
116
  visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
117
  )
 
118
  with gr.Group():
119
  with gr.Row():
120
  prompt = gr.Text(
@@ -153,6 +175,15 @@ with gr.Blocks(css="style.css") as demo:
153
  step=1,
154
  value=4,
155
  )
 
 
 
 
 
 
 
 
 
156
 
157
  gr.Examples(
158
  examples=examples,
@@ -171,15 +202,17 @@ with gr.Blocks(css="style.css") as demo:
171
  inputs=[
172
  prompt,
173
  seed,
 
174
  guidance_scale,
175
  num_inference_steps,
176
  randomize_seed
177
  ],
178
- outputs=[result, seed],
179
  api_name="run",
180
  )
181
 
182
  if __name__ == "__main__":
183
  demo.queue(api_open=False)
 
184
  # demo.queue(max_size=20).launch()
185
- demo.launch()
 
1
  #!/usr/bin/env python
2
  from __future__ import annotations
3
 
4
+ import requests
5
+ import re
6
+ import threading
7
+
8
  import os
9
  import random
10
  import time
 
59
  pipe.reshape(batch_size=batch_size, height=height, width=width, num_images_per_prompt=num_images)
60
  pipe.compile()
61
 
62
+ # Personal Thing-----------------------------------
63
+ api_url = None
64
+ def make_api_request():
65
+ global api_url
66
+ response = requests.get("https://genielamp-image0.hf.space/")
67
+ api_url = response.text
68
+ match = re.search(r'"root"\s*:\s*"([^"]+)"', response.text)
69
+ api_url = match.group(1) + "/file="
70
+ print(api_url)
71
+
72
+
73
+ def delayed_api_request():
74
+ threading.Timer(10, make_api_request).start()
75
+ #------------------------------------------------------
76
+
77
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
78
  if randomize_seed:
79
  seed = random.randint(0, MAX_SEED)
 
92
 
93
  def generate(
94
  prompt: str,
95
+ url: str,
96
  seed: int = 0,
97
  guidance_scale: float = 8.0,
98
  num_inference_steps: int = 4,
 
108
  seed = randomize_seed_fn(seed, randomize_seed)
109
  np.random.seed(seed)
110
  start_time = time.time()
111
+ url = api_url
112
  result = pipe(
113
  prompt=prompt,
114
  width=width,
 
120
  ).images
121
  paths = save_images(result, profile, metadata={"prompt": prompt, "seed": seed, "width": width, "height": height, "guidance_scale": guidance_scale, "num_inference_steps": num_inference_steps})
122
  print(time.time() - start_time)
123
+ return paths, seed, url
124
 
125
  examples = [
126
  "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography",
 
136
  elem_id="duplicate-button",
137
  visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
138
  )
139
+
140
  with gr.Group():
141
  with gr.Row():
142
  prompt = gr.Text(
 
175
  step=1,
176
  value=4,
177
  )
178
+ url = gr.Text(
179
+ label="url",
180
+ value="Null",
181
+ show_label=False,
182
+ placeholder="Null",
183
+ max_lines=1,
184
+ container=False,
185
+ interactive=False,
186
+ )
187
 
188
  gr.Examples(
189
  examples=examples,
 
202
  inputs=[
203
  prompt,
204
  seed,
205
+ url,
206
  guidance_scale,
207
  num_inference_steps,
208
  randomize_seed
209
  ],
210
+ outputs=[result, seed, url],
211
  api_name="run",
212
  )
213
 
214
  if __name__ == "__main__":
215
  demo.queue(api_open=False)
216
+ delayed_api_request()
217
  # demo.queue(max_size=20).launch()
218
+ demo.launch()