awacke1 commited on
Commit
329ec73
1 Parent(s): 60bf8bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -105,23 +105,23 @@ def predict(prompt, guidance, steps, seed=1231231):
105
  if nsfw_content_detected:
106
  nsfw=gr.Button("🕹️NSFW🎨", scale=1)
107
 
108
- central = pytz.timezone('US/Central')
109
- safe_date_time = datetime.datetime.now().strftime("%Y%m%d")
110
- replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
111
- safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:90]
112
- filename = f"{safe_date_time}_{safe_prompt}.png"
113
-
114
-
115
- # Save the image
116
- if len(results.images) > 0:
117
- image_path = os.path.join("", filename) # Specify your directory
118
- results.images[0].save(image_path)
119
- print(f"#Image saved as {image_path}")
120
- encoded_image = encode_image(image)
121
- html_link = f'<a href="data:image/png;base64,{encoded_image}" download="{filename}">Download Image</a>'
122
- gr.Markdown(html_link)
123
-
124
-
125
 
126
  return results.images[0] if len(results.images) > 0 else None
127
 
 
105
  if nsfw_content_detected:
106
  nsfw=gr.Button("🕹️NSFW🎨", scale=1)
107
 
108
+ try:
109
+ central = pytz.timezone('US/Central')
110
+ safe_date_time = datetime.datetime.now().strftime("%Y%m%d")
111
+ replaced_prompt = prompt.replace(" ", "_").replace("\n", "_")
112
+ safe_prompt = "".join(x for x in replaced_prompt if x.isalnum() or x == "_")[:90]
113
+ filename = f"{safe_date_time}_{safe_prompt}.png"
114
+
115
+ # Save the image
116
+ if len(results.images) > 0:
117
+ image_path = os.path.join("", filename) # Specify your directory
118
+ results.images[0].save(image_path)
119
+ print(f"#Image saved as {image_path}")
120
+ encoded_image = encode_image(image)
121
+ html_link = f'<a href="data:image/png;base64,{encoded_image}" download="{filename}">Download Image</a>'
122
+ #gr.Markdown(html_link)
123
+ except:
124
+ return results.images[0]
125
 
126
  return results.images[0] if len(results.images) > 0 else None
127