A simple and fun terminal game that generates AI images using OpenAI’s API — your goal is to guess the original prompt. Each correct answer increases your score… but one wrong guess ends it all!
- 🎲 Picks a random word from a built-in list
- 🖼️ Uses OpenAI’s Image API to generate a picture
- 🕹️ Displays the image and asks you to guess the word
- 🧮 Tracks your score — ends on the first mistake
- ♻️ Lets you restart after each round
- Python
3.8+ - OpenAI API key
- Libraries:
openai,matplotlib,pillow
pip install openai matplotlib pillow
git clone https://github.com/Lundii1/chatgpt-imageguessr
cd chatgpt-imageguessr
Option A — Environment Variable (recommended)
export OPENAI_API_KEY="your_api_key_here" (macOS/Linux)
$env:OPENAI_API_KEY="your_api_key_here" (Windows PowerShell)
Then in your code:
openai.api_key = os.getenv("OPENAI_API_KEY")
Option B — Hardcode (not recommended)
openai.api_key = "your_api_key_here"
Run the game:
python program.py
- The script prints “Loading…” and generates an image.
- The image opens in a pop-up window.
- Type your guess in the terminal.
- If correct → +1 point, new image!
- If wrong → Game over, the answer is revealed.
- Type “yes” to play again.
Change Image Size
size="512x512" — try 1024x1024 for higher quality
Edit or Add Prompts
Modify the dictionnary list at the top of the script.
Fix Restart Command
Replace
os.system("program.py")
with
import sys
os.system(f"{sys.executable} {__file__}")