- About
- Start
- ChatGPT
- DALL·E
- Stable Diffusion
- Account and buy
- API tokens
- Database
- How to deploy
- License
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
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.
If the user wants to chat with ChatGPT, he presses the "💭Chatting — ChatGPT 3.5 Turbo" button and chats.
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.
If the user wants to generate image with DALL·E, he presses the "🌄Image generation — DALL·E" button and generates.
Generated image:
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.
If the user wants to generate image with Stable Diffusion, he presses the "🌅Image generation — Stable Diffusion" button and generates.
Generated 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)
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".
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
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.
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.
After that you need to choose "Deploy from GitHub repo".
Here you need to choose your repository.
After that click "add variables".
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.
Return to your project and add database.
Choose PostgreSQL.
Here you need to press create tables.
For example, tables for this project:
Return to variables and add DATABASE_URL. All variables:
License - this project is licensed under Apache-2.0 license.