Skip to main content

Read a question from a .txt file and turn it into a good looking PyQt5 desktop app that solves it, using Gemini (directly or through a Cloudflare Worker).

Project description

PyQt6-extensions

A command line tool named extend. You put a question in a .txt file, run one command, and it uses Google's Gemini model to write a good looking PyQt5 desktop app that actually solves the question. It launches the app to check it starts without crashing, asks Gemini to fix anything that breaks, and saves the finished program as test.py.

The clever part: instead of putting a Gemini key on every user's machine, the tool can talk to a small Cloudflare Worker that you deploy once. Your Gemini key lives only inside that Worker as a secret, so people can use the tool on your key without ever seeing it.

extend question.txt

What it does

  1. Reads the question from the .txt file you point it at.
  2. Asks how big you want the program (a hint for the model).
  3. Sends the question to Gemini (through your Worker, or directly) and asks for a single file PyQt5 app with a clean, modern window that solves the task.
  4. Launches the generated app headless to make sure it starts. If it crashes, the error goes back to Gemini for a fix (up to --attempts times).
  5. Saves the working app as test.py next to your question file.

Install

pip install .                 # the tool + PyQt5 (needed to run the apps)
pip install ".[direct]"       # also add this if you will call Gemini directly

Once published you would instead run pip install PyQt6-extensions.

Two ways to run it

A) Through your Cloudflare Worker (recommended — your key stays hidden)

Deploy the Worker in cloudflare-worker/ once (steps below), then point the tool at it. Users need no Gemini key of their own.

The easiest way to share it: after you deploy, paste your Worker URL into pyqt6_extensions/config.py:

DEFAULT_WORKER_URL = "https://pyqt6-extensions-worker.YOURNAME.workers.dev"

Now anyone you give these files to can just run extend question.txt with no setup — no key, no URL, no access code. (You can also override per run with --worker-url or the EXTEND_WORKER_URL environment variable.)

B) Directly with your own Gemini key (good for local development)

pip install ".[direct]"
export GEMINI_API_KEY="your_key_here"
extend question.txt --lines 60

If both are set, the Worker wins.

Deploy the Cloudflare Worker

The Worker is the piece that holds your key and calls Gemini. Everything is in cloudflare-worker/.

npm install -g wrangler          # Cloudflare's CLI
cd cloudflare-worker
wrangler login

# store your key as a SECRET (it never lives in the code)
wrangler secret put GEMINI_API_KEY      # paste your Gemini key

wrangler deploy

wrangler deploy prints a URL like https://pyqt6-extensions-worker.YOURNAME.workers.dev. Paste that into pyqt6_extensions/config.py (or share it as EXTEND_WORKER_URL).

  • The GEMINI_API_KEY is a secret, set only with wrangler secret put. It never appears in the code, the repo, or the files you hand out.
  • wrangler.toml ships with ALLOW_OPEN = "true", which means no access code: anyone with the URL can use it. That is what you asked for.
  • If you ever want to lock it down later, delete the ALLOW_OPEN line and run wrangler secret put ACCESS_CODE; callers then pass it with --access-code.

Because it is open, you pay for everyone who has the URL. If usage or cost ever becomes a worry, add an access code or rate limiting.

Use it

Put your question in a text file:

# question.txt
A tip calculator: enter the bill and a tip percent, show the tip and the total.

Then run:

extend question.txt --lines 60

Open the result with python test.py and you get a styled PyQt5 window that does the job.

Run it truly in the background

extend question.txt --lines 60 --background
# returns immediately, keeps working while you use your editor,
# and writes a progress log next to test.py

Make a plain text program instead of a GUI

extend question.txt --lines 20 --plain

Options

Option What it does
--lines N Rough size hint for the model. Asked for if left out.
--worker-url URL Your Cloudflare Worker URL. Falls back to EXTEND_WORKER_URL.
--access-code CODE Access code for the Worker. Falls back to EXTEND_ACCESS_CODE.
--api-key KEY Gemini key for direct calls. Falls back to GEMINI_API_KEY.
--model NAME Gemini model for direct calls. Default gemini-3.1-pro-preview.
--plain Make a simple text program instead of a PyQt5 app.
--output PATH, -o PATH Where to save. Default test.py next to the question.
--attempts N How many times to auto-fix bugs. Default 4.
--background Detach and keep working even if you close the terminal. Needs --lines.
--quiet Print nothing while it works.

How the checking works

  • The code is parsed first, so syntax errors are caught immediately.
  • For a GUI app it is launched headless (QT_QPA_PLATFORM=offscreen). The Qt event loop is short circuited so a healthy app builds its whole window and then exits cleanly. If it crashes while starting, or hangs before the window opens, the error is sent back to Gemini for a fix. This confirms the app really runs, but it cannot prove the answer is correct, so still check the result yourself.
  • If PyQt5 or a display is not available on your machine, the launch step is skipped (the code is still syntax checked) and you are told so.
  • For a --plain program it is run with sample input and a time limit, and any crash or endless loop is sent back for a fix.

A note on the model name

You asked for "Gemini 3.1 pro preview". The real id is gemini-3.1-pro-preview (the older gemini-3-pro-preview was retired). It is the default. If your key is not allow listed for it, both the tool and the Worker fall back to gemini-2.5-pro.

A note on the package name

PyQt6-extensions is the name you chose, so it is what this uses, even though the generated apps use PyQt5. If you ever publish to public PyPI, that name may be flagged as misleading; renaming is just the name field in pyproject.toml.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt6_extensions-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqt6_extensions-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file pyqt6_extensions-0.1.0.tar.gz.

File metadata

  • Download URL: pyqt6_extensions-0.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pyqt6_extensions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3132c8b6926c732671f2eb9c62367735d4959833e0829303c4198f25884e2533
MD5 d7df7c12aa0b28b825ff291d25d7c8bf
BLAKE2b-256 2a5e2904f10e3eef34a62825ac314220550ff1cef1cdb9128777f796255b5340

See more details on using hashes here.

File details

Details for the file pyqt6_extensions-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyqt6_extensions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9949711f01ab3bc3bdfdc09b9be56ee0fbd82efe16661a6bc768167a9800349
MD5 f1b7b4a50d1abf7fde3898990821275f
BLAKE2b-256 fa73b875b8f1836e7994106c5500b68f21c4d720106df13071734af17266b70a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page