A convenient console tool for generating images based on a text description (promt) in Python using the g4f library. It supports several models: Bing, DeepAI, Flux and Pollinations.
-
Choosing a generation model
- Bing (recommended)
- DeepAI
- Flux
- Pollinations
-
The main cycle
-
User input of promt
-
Commands:
exit,выход,quit— terminate the script/model— change the model without restarting
-
-
Result generation and output
-
API request:
response = client.images.generate( model=model, prompt=prompt, response_format="url" ) image_url = response.data[0].url
-
Auto-copying of the link to the clipboard (
pyperclip.copy) -
Beep on successful generation (
winsound.MessageBeep)
-
-
Error handling
-
Interception of exceptions and message output:
Generation error: <error text>
-
- Python 3.7+
- Windows (for
winsoundoperation)
g4fpyperclipwinsound(included in the Windows standard library)
-
Clone the repository:
git clone https://github.com/KiriVoll/AI-Picture-Generator.git cd AI-Picture-Generator -
Install the dependencies:
pip install g4f pyperclip
-
Run the script with the command:
python AIpictureGenerator.py
-
At the first launch, select the generation model (1-4).
-
Enter the promt in the console and press Enter.
-
After generation:
- The link to the image will be copied to the clipboard.
- You will hear a beep.
-
To change the model, enter the command
/model. -
Use
quit,exitorвыходto exit.
The script intercepts all exceptions that occur when accessing the API and outputs them in a clear format. This allows you to continue working after an unsuccessful request.
- Response formats: add support for
base64or byte data - GUI: implement a graphical interface with the
tkinterorPyQtlibraries - Logging: save the history of requests and responses to a file
- Parallel queries: implement batch generation of promts
If you find this useful, feel free to star ⭐ the repo or share your improvements!