Skip to content

This is ChatGPT, DALL·E, Stable Diffusion python-telegram-bot. It allows you to generate images and chat with ChatGPT.

License

Notifications You must be signed in to change notification settings

HoangAnhQuoc/ChatGPT_DALL_E_StableDiffusion_Telegram_Bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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, explain complex concepts and draw pictures according to words. This is Telegram bot written in Python that allows to chat with ChatGPT and generate images using DALL·E and Stable Diffusion. 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 3.5 Turbo", "🌄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 3.5 Turbo" button and chats.

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

In chatgpt.py there are two parameters:

max_tokens - The maximum number of tokens to generate 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 dalle.py there are two parameters:

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 are eight parameters:

engine - Set the engine to use for generation. Available engines: stable-diffusion-v1, stable-diffusion-v1-5, stable-diffusion-512-v2-0, stable-diffusion-768-v2-0, stable-diffusion-512-v2-1, stable-diffusion-768-v2-1, stable-inpainting-v1-0, stable-inpainting-512-v2-0.

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 user wants to buy tokens and generations, he presses "💰Buy tokens and generations" button, selects product and currrency. 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 2023-04-16 19-14-29 online-video-cutter com

API tokens

These project needs these API tokens:

CHAT_GPT3_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

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

Users and information about them will be added to the "users" table, orders would 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 ptoject's variables. For example, for this project you need to add here 4 variables: CHAT_GPT3_API_KEY, CRYPTOPAY_KEY, DATABASE_URL, 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:

image

image

Return to variables and add DATABASE_URL. All variables:

image

License

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

About

This is ChatGPT, DALL·E, Stable Diffusion python-telegram-bot. It allows you to generate images and chat with ChatGPT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Python 99.9%
  • Procfile 0.1%