Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -227,19 +227,97 @@ async def on_message(message:discord.Message):
|
|
227 |
embed.set_image(url=f"attachment://{imgn}.png")
|
228 |
await e.edit(embed=embed, attachments=[file])
|
229 |
|
230 |
-
@bot.
|
231 |
-
async def setup(ctx:discord.
|
232 |
with open(f"{ctx.guild.name}.guild", "a") as f:
|
233 |
f.write(f"{ctx.channel.id}\n")
|
234 |
-
embed = discord.Embed(title="
|
235 |
await ctx.respond(embed=embed)
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
await ctx.respond(embed=embed)
|
242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
def greet(name, intensity):
|
244 |
return "Hello, " + name + "!" * int(intensity)
|
245 |
|
|
|
227 |
embed.set_image(url=f"attachment://{imgn}.png")
|
228 |
await e.edit(embed=embed, attachments=[file])
|
229 |
|
230 |
+
@bot.command(description="Start a chatbot conversation in the channel.")
|
231 |
+
async def setup(ctx:discord.ApplicationContext):
|
232 |
with open(f"{ctx.guild.name}.guild", "a") as f:
|
233 |
f.write(f"{ctx.channel.id}\n")
|
234 |
+
embed = discord.Embed(title="setup", description=f"You can now chat with the bot in <#{ctx.channel.id}>")
|
235 |
await ctx.respond(embed=embed)
|
236 |
+
|
237 |
+
@bot.command(name="reset", description="Reset the chat history of a channel.")
|
238 |
+
@discord.commands.option(
|
239 |
+
"sys",
|
240 |
+
description="The new system prompt.",
|
241 |
+
required=False,
|
242 |
+
default=sysrp
|
243 |
+
)
|
244 |
+
async def reset(ctx:discord.ApplicationContext, sys:str):
|
245 |
+
with open(f"data/{ctx.guild.name}/{ctx.channel.name}", "w") as f:
|
246 |
+
f.write(f"{sot}system: {sys}{eot}")
|
247 |
+
if sys == sysrp:
|
248 |
+
embed = discord.Embed(title="reset", description=f"Reset the channel history with default system prompt.")
|
249 |
+
else:
|
250 |
+
embed = discord.Embed(title="reset", description=f"Reset the channel history with custom system prompt.\n```\n{sys}```")
|
251 |
await ctx.respond(embed=embed)
|
252 |
|
253 |
+
@bot.command(name="create", description="Create an image using a specified model. Defaults to sdxl-turbo.")
|
254 |
+
@discord.commands.option(
|
255 |
+
"prompt",
|
256 |
+
description="The prompt for the image.",
|
257 |
+
required=True,
|
258 |
+
)
|
259 |
+
@discord.commands.option(
|
260 |
+
"model",
|
261 |
+
description="The model to use.",
|
262 |
+
required=False,
|
263 |
+
choices=["Stable Diffusion 2-1", "stable-diffusion-xl-base-1.0", "sdxl-turbo", "sd-turbo"],
|
264 |
+
default="sdxl-turbo"
|
265 |
+
)
|
266 |
+
@discord.commands.option(
|
267 |
+
"negative",
|
268 |
+
description="The negative prompt for the image. Defaults to None.",
|
269 |
+
required=False,
|
270 |
+
default=""
|
271 |
+
)
|
272 |
+
@discord.commands.option(
|
273 |
+
"steps",
|
274 |
+
description="The amount of steps for image generation. Range: 1 - 70.",
|
275 |
+
required=False,
|
276 |
+
default=35
|
277 |
+
)
|
278 |
+
async def create(ctx:discord.ApplicationContext, prompt:str, negative:str, steps:int, model:str):
|
279 |
+
refine = True
|
280 |
+
await ctx.defer()
|
281 |
+
st = time.time()
|
282 |
+
imgn = random.choice(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', 'CA', 'CB', 'CC', 'CD', 'CE', 'CF', 'CG', 'CH', 'CI', 'CJ', 'CK', 'CL', 'CM', 'CN', 'CO', 'CP', 'CQ', 'CR', 'CS', 'CT', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DA', 'DB', 'DC', 'DD', 'DE', 'DF', 'DG', 'DH', 'DI', 'DJ', 'DK', 'DL', 'DM', 'DN', 'DO', 'DP', 'DQ', 'DR', 'DS', 'DT', 'DU', 'DV', 'DW', 'DX', 'DY', 'DZ', 'EA', 'EB', 'EC', 'ED', 'EE', 'EF', 'EG', 'EH', 'EI', 'EJ', 'EK', 'EL', 'EM', 'EN', 'EO', 'EP', 'EQ', 'ER', 'ES', 'ET', 'EU', 'EV', 'EW', 'EX', 'EY', 'EZ', 'FA', 'FB', 'FC', 'FD', 'FE', 'FF', 'FG', 'FH', 'FI', 'FJ', 'FK', 'FL', 'FM', 'FN', 'FO', 'FP', 'FQ', 'FR', 'FS', 'FT', 'FU', 'FV', 'FW', 'FX', 'FY', 'FZ', 'GA', 'GB', 'GC', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GJ', 'GK', 'GL', 'GM', 'GN', 'GO', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GV', 'GW', 'GX', 'GY', 'GZ', 'HA', 'HB', 'HC', 'HD', 'HE', 'HF', 'HG', 'HH', 'HI', 'HJ', 'HK', 'HL', 'HM', 'HN', 'HO', 'HP', 'HQ', 'HR', 'HS', 'HT', 'HU', 'HV', 'HW', 'HX', 'HY', 'HZ', 'IA', 'IB', 'IC', 'ID', 'IE', 'IF', 'IG', 'IH', 'II', 'IJ', 'IK', 'IL', 'IM', 'IN', 'IO', 'IP', 'IQ', 'IR', 'IS', 'IT', 'IU', 'IV', 'IW', 'IX', 'IY', 'IZ', 'JA', 'JB', 'JC', 'JD', 'JE', 'JF', 'JG', 'JH', 'JI', 'JJ', 'JK', 'JL', 'JM', 'JN', 'JO', 'JP', 'JQ', 'JR', 'JS', 'JT', 'JU', 'JV', 'JW', 'JX', 'JY', 'JZ', 'KA', 'KB', 'KC', 'KD', 'KE', 'KF', 'KG', 'KH', 'KI', 'KJ', 'KK', 'KL', 'KM', 'KN', 'KO', 'KP', 'KQ', 'KR', 'KS', 'KT', 'KU', 'KV', 'KW', 'KX', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LD', 'LE', 'LF', 'LG', 'LH', 'LI', 'LJ', 'LK', 'LL', 'LM', 'LN', 'LO', 'LP', 'LQ', 'LR', 'LS', 'LT', 'LU', 'LV', 'LW', 'LX', 'LY', 'LZ', 'MA', 'MB', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MI', 'MJ', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NB', 'NC', 'ND', 'NE', 'NF', 'NG', 'NH', 'NI', 'NJ', 'NK', 'NL', 'NM', 'NN', 'NO', 'NP', 'NQ', 'NR', 'NS', 'NT', 'NU', 'NV', 'NW', 'NX', 'NY', 'NZ', 'OA', 'OB', 'OC', 'OD', 'OE', 'OF', 'OG', 'OH', 'OI', 'OJ', 'OK', 'OL', 'OM', 'ON', 'OO', 'OP', 'OQ', 'OR', 'OS', 'OT', 'OU', 'OV', 'OW', 'OX', 'OY', 'OZ', 'PA', 'PB', 'PC', 'PD', 'PE', 'PF', 'PG', 'PH', 'PI', 'PJ', 'PK', 'PL', 'PM', 'PN', 'PO', 'PP', 'PQ', 'PR', 'PS', 'PT', 'PU', 'PV', 'PW', 'PX', 'PY', 'PZ', 'QA', 'QB', 'QC', 'QD', 'QE', 'QF', 'QG', 'QH', 'QI', 'QJ', 'QK', 'QL', 'QM', 'QN', 'QO', 'QP', 'QQ', 'QR', 'QS', 'QT', 'QU', 'QV', 'QW', 'QX', 'QY', 'QZ', 'RA', 'RB', 'RC', 'RD', 'RE', 'RF', 'RG', 'RH', 'RI', 'RJ', 'RK', 'RL', 'RM', 'RN', 'RO', 'RP', 'RQ', 'RR', 'RS', 'RT', 'RU', 'RV', 'RW', 'RX', 'RY', 'RZ', 'SA', 'SB', 'SC', 'SD', 'SE', 'SF', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SP', 'SQ', 'SR', 'SS', 'ST', 'SU', 'SV', 'SW', 'SX', 'SY', 'SZ', 'TA', 'TB', 'TC', 'TD', 'TE', 'TF', 'TG', 'TH', 'TI', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TP', 'TQ', 'TR', 'TS', 'TT', 'TU', 'TV', 'TW', 'TX', 'TY', 'TZ', 'UA', 'UB', 'UC', 'UD', 'UE', 'UF', 'UG', 'UH', 'UI', 'UJ', 'UK', 'UL', 'UM', 'UN', 'UO', 'UP', 'UQ', 'UR', 'US', 'UT', 'UU', 'UV', 'UW', 'UX', 'UY', 'UZ', 'VA', 'VB', 'VC', 'VD', 'VE', 'VF', 'VG', 'VH', 'VI', 'VJ', 'VK', 'VL', 'VM', 'VN', 'VO', 'VP', 'VQ', 'VR', 'VS', 'VT', 'VU', 'VV', 'VW', 'VX', 'VY', 'VZ', 'WA', 'WB', 'WC', 'WD', 'WE', 'WF', 'WG', 'WH', 'WI', 'WJ', 'WK', 'WL', 'WM', 'WN', 'WO', 'WP', 'WQ', 'WR', 'WS', 'WT', 'WU', 'WV', 'WW', 'WX', 'WY', 'WZ', 'XA', 'XB', 'XC', 'XD', 'XE', 'XF', 'XG', 'XH', 'XI', 'XJ', 'XK', 'XL', 'XM', 'XN', 'XO', 'XP', 'XQ', 'XR', 'XS', 'XT', 'XU', 'XV', 'XW', 'XX', 'XY', 'XZ', 'YA', 'YB', 'YC', 'YD', 'YE', 'YF', 'YG', 'YH', 'YI', 'YJ', 'YK', 'YL', 'YM', 'YN', 'YO', 'YP', 'YQ', 'YR', 'YS', 'YT', 'YU', 'YV', 'YW', 'YX', 'YY', 'YZ', 'ZA', 'ZB', 'ZC', 'ZD', 'ZE', 'ZF', 'ZG', 'ZH', 'ZI', 'ZJ', 'ZK', 'ZL', 'ZM', 'ZN', 'ZO', 'ZP', 'ZQ', 'ZR', 'ZS', 'ZT', 'ZU', 'ZV', 'ZW', 'ZX', 'ZY', 'ZZ'])
|
283 |
+
if not 1 <= steps <= 70:
|
284 |
+
embed = discord.Embed(title="Invalid Step Count", description=f"Please enter a number between 1 and 70.")
|
285 |
+
await ctx.respond(embed=embed)
|
286 |
+
return
|
287 |
+
if model == "Stable Diffusion 2-1":
|
288 |
+
image, m = (await SD.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps), "Stable Diffusion 2-1")
|
289 |
+
elif model == "stable-diffusion-xl-base-1.0":
|
290 |
+
image, m = (await SDXL.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps), "stable-diffusion-xl-base-1.0")
|
291 |
+
elif model == "sdxl-turbo":
|
292 |
+
image, m = (await SDXLT.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps, guidance_scale=0.0), "sdxl-turbo")
|
293 |
+
elif model == "sd-turbo":
|
294 |
+
image, m = (await SDT.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps, guidance_scale=0.0), "sd-turbo")
|
295 |
+
elif model == "Proteus v0.2":
|
296 |
+
image, m = (await PT.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps), "Proteus v0.2")
|
297 |
+
else:
|
298 |
+
raise NotImplementedError(f"Model {imageModel} not found. Report this to @araeyn if this keeps happening.")
|
299 |
+
embed = discord.Embed(title="create", description=f"```\n{prompt}\n```")
|
300 |
+
image.save(f"{imgn}.png")
|
301 |
+
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png", description=prompt)
|
302 |
+
embed.set_image(url=f"attachment://{imgn}.png")
|
303 |
+
gt = time.time()
|
304 |
+
image, r = (await RF.image_to_image(f"{imgn}.png", num_inference_steps=35, prompt=prompt, negative_prompt=negative), "stable-diffusion-xl-refiner-1.0")
|
305 |
+
rt = time.time()
|
306 |
+
if refine:
|
307 |
+
embed.set_footer(
|
308 |
+
text=
|
309 |
+
f"Image generation model is {m}. Refiner model is {r}. Took {round((gt - st) * 100) / 100} seconds to generate. Took {round((rt - gt) * 100) / 100} seconds to refine."
|
310 |
+
)
|
311 |
+
else:
|
312 |
+
embed.set_footer(
|
313 |
+
text=
|
314 |
+
f"Image generation model is {m}. Took {round((gt - st) * 100) / 100} seconds to generate."
|
315 |
+
)
|
316 |
+
image.save(f"{imgn}.png")
|
317 |
+
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png")
|
318 |
+
embed.set_image(url=f"attachment://{imgn}.png")
|
319 |
+
await ctx.respond(embed=embed, file=file)
|
320 |
+
|
321 |
def greet(name, intensity):
|
322 |
return "Hello, " + name + "!" * int(intensity)
|
323 |
|