yuval added negativew prompts

This commit is contained in:
yair 2023-04-22 22:15:16 +03:00
parent 4cfa3e9812
commit 63cd9f2a38

30
main.py
View File

@ -32,18 +32,34 @@ app = Client(
) )
def slice_positive_negative(string):
delimiter = "ng"
if delimiter in string:
index = string.index(delimiter)
positive = string[:index].rstrip()
negative = string[index+len(delimiter):].lstrip()
return positive, negative
else:
return string, "null" #if we are missing the ng bad thing happen....
@app.on_message(filters.command(["draw"])) @app.on_message(filters.command(["draw"]))
def draw(client, message): def draw(client, message):
msgs = message.text.split(' ', 1) msgs = message.text.split(' ', 1)
if len(msgs) == 1: if len(msgs) == 1:
message.reply_text("Format : /draw < text to image >") message.reply_text("Format :\n/draw < text to image >\nng < negative (optional) >")
return return
msg = msgs[1]
msg = slice_positive_negative(msgs[1])
print(msg)
payload = {
"prompt": msg[0],
"negative_prompt": msg[1],
}
print(payload)
K = message.reply_text("Please Wait 10-15 Second") K = message.reply_text("Please Wait 10-15 Second")
payload = {"prompt": msg}
r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json() r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json()
# explaination # explaination
@ -77,9 +93,9 @@ def draw(client, message):
message.reply_photo( message.reply_photo(
photo=f"{word}.png", photo=f"{word}.png",
caption= caption=
f"Prompt - **{msg}**\n **[{message.from_user.first_name}-Kun](tg://user?id={message.from_user.id})**" f"Prompt - **{msg[0]}**\nNegative Prompt - **{msg[1]}**\n**[{message.from_user.first_name}-Kun](tg://user?id={message.from_user.id})**"
) )
os.remove(f"{word}.png") # os.remove(f"{word}.png")
K.delete() K.delete()