diff --git a/img_api.py b/img_api.py new file mode 100644 index 0000000..417bc3f --- /dev/null +++ b/img_api.py @@ -0,0 +1,26 @@ +from gradio_client import Client + +# Пользователь - сессия +img_ses = {} + +def draw(prompt, id): + global img_ses + if str(id) not in img_ses: + client = Client("https://playgroundai-playground-v2-5.hf.space/--replicas/0czym/") + img_ses[str(id)] = client + else: + client = img_ses[str(id)] + + result = client.predict( + prompt, # Что рисуем + "", # 'Negative prompt' + False, # 'Use negative prompt' + 0, # Сид + 512, # float (numeric value between 256 and 1536) in 'Width' Slider component + 512, # float (numeric value between 256 and 1536) in 'Height' Slider component + 3, # float (numeric value between 0.1 and 20) in 'Guidance Scale' Slider component + True, # bool in 'Randomize seed' Checkbox component + api_name="/run") + + # Путь к изображению + return result[0][0]["image"] diff --git a/minigpt.py b/minigpt.py index b677fc5..289b219 100755 --- a/minigpt.py +++ b/minigpt.py @@ -47,13 +47,21 @@ cp - Сбросить инструкцию ### MAIN ### from api import * +from img_api import * import traceback import logging +# Заданные модели setted_models = {} +# Системные инструкции system_prompts = {} -onoff = {} + +# Размер изображения +img_size = {} + + +######### INFO AND HELP ################# @bot.message_handler(commands=['info','i']) def info(message): @@ -106,7 +114,7 @@ def callback_query(call): setted_models[id] = m bot.edit_message_text(f"Успешно установлена модель {m} 🤖", chat_id = c_id, message_id = m_id) -########################################## +############### PROMPT ################### @bot.message_handler(commands=['p']) def set_prompt(message): @@ -137,6 +145,28 @@ def clear_context(message): bot.reply_to(message, "Контекст очищен 🤖") +############### IMG #################### + +@bot.message_handler(commands=['img']) +def draw_image(message): + mm = bot.send_message(message.chat.id, "Генерируем изображение...") + try: + m_id = mm.id + prompt = " ".join( message.text.split()[1:] ) + + img_way = draw(prompt, message.chat.id) + with open(img_way, 'rb') as f: + img = f.read() + f.close() + + bot.send_photo(message.chat.id, img, f'{telebot.formatting.hcode(prompt)}', parse_mode="HTML") + bot.delete_message(message.chat.id, m_id) + except: + bot.send_message(message.chat.id, "Извините, возникла непредвиденная ошибка") + + +########################################## + @bot.message_handler(func=lambda message: True) def echo_message(message): # Отвечаем в ЛС, либо по команде