Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -280,7 +280,7 @@ async def setup(ctx:discord.ApplicationContext):
|
|
280 |
embed = discord.Embed(title="setup", description=f"You can now chat with the bot in <#{ctx.channel.id}>")
|
281 |
await ctx.respond(embed=embed)
|
282 |
|
283 |
-
@bot.command(name="reset", description="
|
284 |
@discord.commands.option(
|
285 |
"sys",
|
286 |
description="The new system prompt.",
|
@@ -296,11 +296,64 @@ async def reset(ctx:discord.ApplicationContext, sys:str):
|
|
296 |
embed = discord.Embed(title="reset", description=f"Reset the channel history with custom system prompt.\n```\n{sys}```")
|
297 |
await ctx.respond(embed=embed)
|
298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
def reverse(filepath):
|
300 |
with open(filepath, "r") as f:
|
301 |
return f.read()
|
302 |
|
303 |
demo = gr.Interface(reverse, "text", "text")
|
304 |
|
305 |
-
Process(target=demo.launch, kwargs={"auth":("
|
306 |
Process(target=bot.run, args=[os.environ.get("TOKEN")]).start()
|
|
|
280 |
embed = discord.Embed(title="setup", description=f"You can now chat with the bot in <#{ctx.channel.id}>")
|
281 |
await ctx.respond(embed=embed)
|
282 |
|
283 |
+
@bot.command(name="reset", description="Reset the chat history of a channel.")
|
284 |
@discord.commands.option(
|
285 |
"sys",
|
286 |
description="The new system prompt.",
|
|
|
296 |
embed = discord.Embed(title="reset", description=f"Reset the channel history with custom system prompt.\n```\n{sys}```")
|
297 |
await ctx.respond(embed=embed)
|
298 |
|
299 |
+
@bot.command(name="create", description="Create an image using a specified model. Defaults to sdxl-turbo.")
|
300 |
+
@discord.commands.option(
|
301 |
+
"prompt",
|
302 |
+
description="The prompt for the image.",
|
303 |
+
required=True,
|
304 |
+
)
|
305 |
+
@discord.commands.option(
|
306 |
+
"model",
|
307 |
+
description="The model to use.",
|
308 |
+
required=False,
|
309 |
+
choices=["Stable Diffusion 2-1", "stable-diffusion-xl-base-1.0", "sdxl-turbo", "sd-turbo"],
|
310 |
+
default="sdxl-turbo"
|
311 |
+
)
|
312 |
+
async def create(ctx:discord.ApplicationContext, prompt:str, model:str, negative:str, steps:int):
|
313 |
+
await ctx.defer()
|
314 |
+
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'])
|
315 |
+
if not 1 <= steps <= 70:
|
316 |
+
embed = discord.Embed(title="Invalid Step Count", description=f"Please enter a number between 1 and 70.")
|
317 |
+
await ctx.respond(embed=embed)
|
318 |
+
return
|
319 |
+
if model == "Stable Diffusion 2-1":
|
320 |
+
image, m = (await SD.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps), "Stable Diffusion 2-1")
|
321 |
+
elif model == "stable-diffusion-xl-base-1.0":
|
322 |
+
image, m = (await SDXL.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps), "stable-diffusion-xl-base-1.0")
|
323 |
+
elif model == "sdxl-turbo":
|
324 |
+
image, m = (await SDXLT.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps, guidance_scale=0.0), "sdxl-turbo")
|
325 |
+
elif model == "sd-turbo":
|
326 |
+
image, m = (await SDT.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps, guidance_scale=0.0), "sd-turbo")
|
327 |
+
elif model == "Proteus v0.2":
|
328 |
+
image, m = (await PT.text_to_image(prompt=prompt, negative_prompt=negative, num_inference_steps=steps), "Proteus v0.2")
|
329 |
+
else:
|
330 |
+
raise NotImplementedError(f"Model {imageModel} not found. Report this to @araeyn if this keeps happening.")
|
331 |
+
embed = discord.Embed(title="create", description=f"```\n{prompt}\n```")
|
332 |
+
image.save(f"{imgn}.png")
|
333 |
+
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png", description=prompt)
|
334 |
+
embed.set_image(url=f"attachment://{imgn}.png")
|
335 |
+
embed.set_footer(
|
336 |
+
text=
|
337 |
+
"""Refining..."""
|
338 |
+
)
|
339 |
+
await e.edit(embed=embed, attachments=[], file=file)
|
340 |
+
gt = time.time()
|
341 |
+
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")
|
342 |
+
rt = time.time()
|
343 |
+
embed.set_footer(
|
344 |
+
text=
|
345 |
+
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."
|
346 |
+
)
|
347 |
+
image.save(f"{imgn}.png")
|
348 |
+
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png")
|
349 |
+
embed.set_image(url=f"attachment://{imgn}.png")
|
350 |
+
await ctx.respond(embed=embed, file=file)
|
351 |
+
|
352 |
def reverse(filepath):
|
353 |
with open(filepath, "r") as f:
|
354 |
return f.read()
|
355 |
|
356 |
demo = gr.Interface(reverse, "text", "text")
|
357 |
|
358 |
+
Process(target=demo.launch, kwargs={"auth":("araeyn", "araeyn")}).start()
|
359 |
Process(target=bot.run, args=[os.environ.get("TOKEN")]).start()
|