nyanko7 commited on
Commit
840313a
1 Parent(s): d0133b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -18
app.py CHANGED
@@ -29,9 +29,9 @@ def save_to_s3(image_data, payload, file_name):
29
  payload_data = io.BytesIO(payload.encode('utf-8'))
30
  s3.upload_fileobj(payload_data, bucket_name, payload_key, ExtraArgs={'ContentType': 'application/json'})
31
 
32
- import concurrent
33
  # Function to handle the NovelAI API request
34
- def generate_novelai_image(input_text, quality_tags, seed, negative_prompt, scale, ratio, sampler, progress=gr.Progress()):
35
  jwt_token = os.environ.get('NAI_API_KEY')
36
  if ratio == "Landscape (1216x832)":
37
  width = 1216
@@ -92,20 +92,6 @@ def generate_novelai_image(input_text, quality_tags, seed, negative_prompt, scal
92
  }
93
  }
94
 
95
- futures = []
96
- with concurrent.futures.ThreadPoolExecutor() as executor:
97
- future = executor.submit(request_novelai, url, payload, headers)
98
- futures.append(future)
99
-
100
- for _ in progress.tqdm([None] * 15, desc="Generating"):
101
- done, not_done = concurrent.futures.wait(futures, timeout=np.random.uniform(0.8, 1.4))
102
- if len(not_done) == 0:
103
- break
104
- return futures[0].result()
105
-
106
-
107
- def request_novelai(url, payload, headers):
108
-
109
  # Send the POST request
110
  response = requests.post(url, json=payload, headers=headers)
111
 
@@ -122,7 +108,7 @@ def request_novelai(url, payload, headers):
122
  buffered = io.BytesIO()
123
  image.save(buffered, format="WEBP", quality=98)
124
  file_name = str(int(datetime.datetime.now().timestamp()))
125
- # save_to_s3(buffered, json.dumps(payload, indent=4), file_name)
126
 
127
  return np.array(image), json.dumps(payload, indent=4)
128
 
@@ -131,7 +117,6 @@ def request_novelai(url, payload, headers):
131
  else:
132
  return "The response is not a zip file.", json.dumps(payload, indent=4)
133
 
134
-
135
  # Create Gradio interface
136
  iface = gr.Interface(
137
  fn=generate_novelai_image,
 
29
  payload_data = io.BytesIO(payload.encode('utf-8'))
30
  s3.upload_fileobj(payload_data, bucket_name, payload_key, ExtraArgs={'ContentType': 'application/json'})
31
 
32
+
33
  # Function to handle the NovelAI API request
34
+ def generate_novelai_image(input_text, quality_tags, seed, negative_prompt, scale, ratio, sampler):
35
  jwt_token = os.environ.get('NAI_API_KEY')
36
  if ratio == "Landscape (1216x832)":
37
  width = 1216
 
92
  }
93
  }
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  # Send the POST request
96
  response = requests.post(url, json=payload, headers=headers)
97
 
 
108
  buffered = io.BytesIO()
109
  image.save(buffered, format="WEBP", quality=98)
110
  file_name = str(int(datetime.datetime.now().timestamp()))
111
+ save_to_s3(buffered, json.dumps(payload, indent=4), file_name)
112
 
113
  return np.array(image), json.dumps(payload, indent=4)
114
 
 
117
  else:
118
  return "The response is not a zip file.", json.dumps(payload, indent=4)
119
 
 
120
  # Create Gradio interface
121
  iface = gr.Interface(
122
  fn=generate_novelai_image,