Nima nazari commited on
Commit
8f70b42
·
verified ·
1 Parent(s): 72c37fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -10,8 +10,8 @@ import requests
10
 
11
  from PIL import Image
12
 
13
-
14
- URL = "http://127.0.0.1:8188/prompt"
15
  INPUT_DIR = "input"
16
  OUTPUT_DIR = "output"
17
 
@@ -24,41 +24,51 @@ def get_latest_image(folder):
24
  latest_image = os.path.join(folder, image_files[-1]) if image_files else None
25
  return latest_image
26
 
 
27
 
28
  def start_queue(prompt_workflow):
29
  p = {"prompt": prompt_workflow}
30
  data = json.dumps(p).encode('utf-8')
31
  requests.post(URL, data=data)
32
 
 
33
 
34
  def generate_image(input_image):
35
  with open("workflow.json", "r") as file_json:
36
  prompt = json.load(file_json)
 
37
 
38
  prompt["3"]["inputs"]["seed"] = random.randint(1, 1500000)
39
  global cached_seed
40
  if cached_seed == prompt["3"]["inputs"]["seed"]:
41
  return get_latest_image(OUTPUT_DIR)
42
  cached_seed = prompt["3"]["inputs"]["seed"]
 
43
 
44
  image = Image.fromarray(input_image)
45
  min_side = min(image.size)
46
  scale_factor = 512 / min_side
47
  new_size = (round(image.size[0] * scale_factor), round(image.size[1] * scale_factor))
48
  resized_image = image.resize(new_size)
 
49
 
50
  resized_image.save(os.path.join(INPUT_DIR, "test_api.jpg"))
51
 
52
  previous_image = get_latest_image(OUTPUT_DIR)
53
 
54
  start_queue(prompt)
 
55
 
56
  while True:
 
 
57
  latest_image = get_latest_image(OUTPUT_DIR)
58
  if latest_image != previous_image:
59
  return latest_image
 
60
 
61
  time.sleep(1)
62
 
63
  demo = gr.Interface(fn=generate_image, inputs=["image"], outputs=["image"])
64
- demo.launch(share=True)
 
 
10
 
11
  from PIL import Image
12
 
13
+ print ("1")
14
+ URL = "http://0.0.0.0:8188/prompt"
15
  INPUT_DIR = "input"
16
  OUTPUT_DIR = "output"
17
 
 
24
  latest_image = os.path.join(folder, image_files[-1]) if image_files else None
25
  return latest_image
26
 
27
+ print ("2")
28
 
29
  def start_queue(prompt_workflow):
30
  p = {"prompt": prompt_workflow}
31
  data = json.dumps(p).encode('utf-8')
32
  requests.post(URL, data=data)
33
 
34
+ print ("3")
35
 
36
  def generate_image(input_image):
37
  with open("workflow.json", "r") as file_json:
38
  prompt = json.load(file_json)
39
+ print ("4")
40
 
41
  prompt["3"]["inputs"]["seed"] = random.randint(1, 1500000)
42
  global cached_seed
43
  if cached_seed == prompt["3"]["inputs"]["seed"]:
44
  return get_latest_image(OUTPUT_DIR)
45
  cached_seed = prompt["3"]["inputs"]["seed"]
46
+ print ("5")
47
 
48
  image = Image.fromarray(input_image)
49
  min_side = min(image.size)
50
  scale_factor = 512 / min_side
51
  new_size = (round(image.size[0] * scale_factor), round(image.size[1] * scale_factor))
52
  resized_image = image.resize(new_size)
53
+ print ("6")
54
 
55
  resized_image.save(os.path.join(INPUT_DIR, "test_api.jpg"))
56
 
57
  previous_image = get_latest_image(OUTPUT_DIR)
58
 
59
  start_queue(prompt)
60
+ print ("7")
61
 
62
  while True:
63
+ print ("8")
64
+
65
  latest_image = get_latest_image(OUTPUT_DIR)
66
  if latest_image != previous_image:
67
  return latest_image
68
+ print ("9")
69
 
70
  time.sleep(1)
71
 
72
  demo = gr.Interface(fn=generate_image, inputs=["image"], outputs=["image"])
73
+ demo.launch(share=True)
74
+ print ("10")