Skip to content

ilya-88/Mybot

Repository files navigation

ChatGPT, DALL·E, Stable Diffusion Telegram bot

Table of Contents

About

Nowadays neural networks are able to conduct a dialogue, quickly search for the information we need, answer questions and draw pictures from words. This is a Telegram bot written in Python that allows you to chat with ChatGPT and generate images using DALL·E and Stable Diffusion, payments are implemented using Crypto Bot. I think it is very comfortable to unite these neural networks in one Telegram bot.

You can look on this bot in Telegram: @ChatGpt_Dall_E_Bot

Start

When the user enters the start command, the bot sends him a welcome message stating that the user has free 3000 ChatGPT tokens, 3 DALL·E image generations and 3 Stable Diffusion image generations and displays 4 buttons: "💭Chatting — ChatGPT", "🌄Image generation — DALL·E", "🌅Image generation — Stable Diffusion" and "👤My account | 💰Buy". If the user is already registered, the bot only displays buttons.

ChatGPT, DALL·E, Stable Diffusion _ Telegram bot 2023-04-16 18-14-35 online-video-cutter com

ChatGPT

If the user wants to chat with ChatGPT, he presses the "💭Chatting — ChatGPT" button and chats.

ChatGPT, DALL·E, Stable Diffusion _ Telegram bot 2023-04-16 18-34-00 online-video-cutter com

In openaitools.py in the OpenAiTools class there are three parameters in the get_chatgpt function:

model - The model which is used for generation.

max_tokens - The maximum number of tokens that can be generated in the chat completion.

temperature - What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

DALL·E

If the user wants to generate image with DALL·E, he presses the "🌄Image generation — DALL·E" button and generates.

ChatGPT, DALL·E, Stable Diffusion _ Telegram bot – 1 2023-04-16 18-47-44 online-video-cutter com (1)

Generated image:

photo_2023-04-16_18-47-57

In openaitools.py in the OpenAiTools class there are three parameters in the get_dalle function:

model - The model which is used for generation.

n - The number of images to generate. Must be between 1 and 10.

size - The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.

Stable Diffusion

If the user wants to generate image with Stable Diffusion, he presses the "🌅Image generation — Stable Diffusion" button and generates.

ChatGPT, DALL·E, Stable Diffusion _ Telegram bot 2023-04-16 19-06-33 online-video-cutter com

Generated image:

image

In stablediffusion.py there is one parameter:

engine - Set the engine to use for generation. Available engines: stable-diffusion-xl-1024-v0-9, stable-diffusion-xl-1024-v1-0, esrgan-v1-x2plus.

Also in the StableDiffusion class there are seven parameters in the get_stable function:

seed - If a seed is provided, the resulting generated image will be deterministic. What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.

steps - Amount of inference steps performed on image generation. Defaults to 30.

cfg_scale - Influences how strongly your generation is guided to match your prompt. Setting this value higher increases the strength in which it tries to match your prompt. Defaults to 7.0 if not specified.

width - Generation width, defaults to 512 if not included.

height - Generation height, defaults to 512 if not included.

samples - Number of images to generate, defaults to 1 if not included.

sampler - Choose which sampler we want to denoise our generation with. Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers. (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m)

Account and buy

If the user wants to see account information or buy tokens and generations, he presses the "👤My account | 💰Buy" button. After pressing the button, the bot displays information about the rest of the user's ChatGPT tokens, DALL·E image generations and Stable Diffusion image generations. If the user wants to buy tokens and generations, he presses the "💰Buy tokens and generations" button, selects the product and currency. After that, the user needs to press the "💰Buy" button and pay in Crypto Bot if he wants to pay. If the user has paid, he should press "☑️Check" button and tokens or image generations will be added to his account. If the user hasn't paid, the bot will display the message "⌚️We have not received payment yet".

ChatGPT, DALL·E, Stable Diffusion _ Telegram bot 2024-02-05 21-52-10 (8)

API tokens

These project needs these API tokens:

OPENAI_API_KEY - OpenAI API key which you can get here: OpenAI API key

STABLE_DIFFUSION_API_KEY - Stable Diffusion API key which you can get here: Stable Diffusion API key

TELEGRAM_BOT_TOKEN - Telegram Bot API key which you can get here after creation of your bot: @BotFather

CRYPTOPAY_KEY - Crypto Bot API key which you can get here after registration in bot (Crypto Pay - Create App): @CryptoBot

Database

This project requires PostgreSQL database with two tables: orders(invoice_id, user_id, product) and users(user_id, username, chatgpt, dall_e, stable_diffusion).

Users and information about them will be added to the "users" table, orders will be added to the "orders" table.

DATABASE_URL - url to database.

How to deploy

This project was deployed on the Railway.

For deployment you just need to create the GitHub repository, click "Start a New Project" button on the Railway website.

image

After that you need to choose "Deploy from GitHub repo".

image

Here you need to choose your repository.

image

After that click "add variables".

image

Add your project's variables. For example, for this project you need to add here 4 variables: CRYPTOPAY_KEY, OPENAI_API_KEY, STABLE_DIFFUSION_API_KEY and TELEGRAM_BOT_TOKEN.

image

Return to your project and add database.

image

Choose PostgreSQL.

image

Here you need to press create tables.

image

For example, tables for this project:

imm

image

Return to variables and add DATABASE_URL. All variables:

image

License

License - this project is licensed under Apache-2.0 license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published