Добавлена генерация изображений.
This commit is contained in:
parent
93e39bdb53
commit
8b9c984fc1
26
img_api.py
Normal file
26
img_api.py
Normal file
@ -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"]
|
34
minigpt.py
34
minigpt.py
@ -47,13 +47,21 @@ cp - Сбросить инструкцию
|
|||||||
|
|
||||||
### MAIN ###
|
### MAIN ###
|
||||||
from api import *
|
from api import *
|
||||||
|
from img_api import *
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
# Заданные модели
|
||||||
setted_models = {}
|
setted_models = {}
|
||||||
|
# Системные инструкции
|
||||||
system_prompts = {}
|
system_prompts = {}
|
||||||
onoff = {}
|
|
||||||
|
# Размер изображения
|
||||||
|
img_size = {}
|
||||||
|
|
||||||
|
|
||||||
|
######### INFO AND HELP #################
|
||||||
|
|
||||||
@bot.message_handler(commands=['info','i'])
|
@bot.message_handler(commands=['info','i'])
|
||||||
def info(message):
|
def info(message):
|
||||||
@ -106,7 +114,7 @@ def callback_query(call):
|
|||||||
setted_models[id] = m
|
setted_models[id] = m
|
||||||
bot.edit_message_text(f"Успешно установлена модель {m} 🤖", chat_id = c_id, message_id = m_id)
|
bot.edit_message_text(f"Успешно установлена модель {m} 🤖", chat_id = c_id, message_id = m_id)
|
||||||
|
|
||||||
##########################################
|
############### PROMPT ###################
|
||||||
|
|
||||||
@bot.message_handler(commands=['p'])
|
@bot.message_handler(commands=['p'])
|
||||||
def set_prompt(message):
|
def set_prompt(message):
|
||||||
@ -137,6 +145,28 @@ def clear_context(message):
|
|||||||
bot.reply_to(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)
|
@bot.message_handler(func=lambda message: True)
|
||||||
def echo_message(message):
|
def echo_message(message):
|
||||||
# Отвечаем в ЛС, либо по команде
|
# Отвечаем в ЛС, либо по команде
|
||||||
|
Loading…
Reference in New Issue
Block a user