Flask LLM Renderer
Overview
Another project on my journey to never write frontend code again. This is a decorator for Flask that allows you to render HTML from any recieved json response to a HTML page, that is updated in real-time to a server through websockets. (99 percent of this project was spent refining the html prompt :D)
Note: initial render is super slow for flask root view (probably due to eventlet and anthropic api conflict, silly bug), but after its ok :(
Installation
We can either pip install flask_llm_renderer the package from PyPI or clone the repository and install it manually:
pip install build
python -m build
pip install dist/*.whl
Example Usage
python examples/example.py
You should be able to access the example at http://localhost:5000/. The example uses a simple Flask app that renders an initially empty page.
After you can curl a request to dynamically render an llm generated HTML page:
curl -X POST http://127.0.0.1:5000/render \
-H "Content-Type: application/json" \
-d '{
"prompt": {
"location": "London",
"forecast": [
{"day": "Monday", "high": 18, "low": 10, "condition": "Rainy"},
{"day": "Tuesday", "high": 20, "low": 11, "condition": "Cloudy"},
{"day": "Wednesday", "high": 22, "low": 12, "condition": "Sunny"}
]
}
}'
you should see something like this in your browser:
Another example is:
curl -X POST http://127.0.0.1:5000/render \
-H "Content-Type: application/json" \
-d '{
"title": "30-Day Stock Price Comparison",
"stocks": [
{
"symbol": "AAPL",
"prices": [192.4, 193.1, 194.0, 193.5, 192.8, 195.0, 196.2, 197.1, 198.4, 199.0, 198.7, 198.2, 199.3, 200.0, 201.4, 202.3, 201.7, 202.8, 203.5, 204.1, 203.9, 202.6, 201.8, 202.0, 203.2, 204.4, 205.1, 204.7, 205.5, 206.0]
},
{
"symbol": "MSFT",
"prices": [318.9, 320.2, 319.5, 318.0, 319.0, 320.1, 321.4, 322.2, 321.6, 322.0, 323.1, 324.0, 325.5, 326.2, 327.0, 326.5, 327.8, 328.0, 329.1, 330.0, 331.2, 330.7, 329.9, 330.3, 331.0, 332.5, 333.2, 332.8, 333.5, 334.1]
}
],
"dates": [
"Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Day 8", "Day 9", "Day 10",
"Day 11", "Day 12", "Day 13", "Day 14", "Day 15", "Day 16", "Day 17", "Day 18", "Day 19", "Day 20",
"Day 21", "Day 22", "Day 23", "Day 24", "Day 25", "Day 26", "Day 27", "Day 28", "Day 29", "Day 30"
]
}'
You should see something like this in your browser:
If you want specific styling, you can add extra detail in the 'extra-details' field in the json request:
curl -X POST http://127.0.0.1:5000/render \
-H "Content-Type: application/json" \
-d '{
"title": "30-Day Stock Price Comparison",
"stocks": [
{
"symbol": "AAPL",
"prices": [192.4, 193.1, 194.0, 193.5, 192.8, 195.0, 196.2, 197.1, 198.4, 199.0, 198.7, 198.2, 199.3, 200.0, 201.4, 202.3, 201.7, 202.8, 203.5, 204.1, 203.9, 202.6, 201.8, 202.0, 203.2, 204.4, 205.1, 204.7, 205.5, 206.0]
},
{
"symbol": "MSFT",
"prices": [318.9, 320.2, 319.5, 318.0, 319.0, 320.1, 321.4, 322.2, 321.6, 322.0, 323.1, 324.0, 325.5, 326.2, 327.0, 326.5, 327.8, 328.0, 329.1, 330.0, 331.2, 330.7, 329.9, 330.3, 331.0, 332.5, 333.2, 332.8, 333.5, 334.1]
}
],
"dates": [
"Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Day 8", "Day 9", "Day 10",
"Day 11", "Day 12", "Day 13", "Day 14", "Day 15", "Day 16", "Day 17", "Day 18", "Day 19", "Day 20",
"Day 21", "Day 22", "Day 23", "Day 24", "Day 25", "Day 26", "Day 27", "Day 28", "Day 29", "Day 30"
],
"extra-details": "AT the top give me a pie chart of the prices of each stock (total is the pie) and slice it based on price of each stock, after plot me the moving average of both stocks below a chart of the stock prices. Use a blue line for AAPL and a red line for MSFT. Make sure the chart is clear and easy to read. Then give me a wuick summary on the stock performance over the 30 days, highlighting any significant trends or patterns."
}'
You should see something like this in your browser:
Metadata
Release files for flask-llm-renderer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flask_llm_renderer-0.1.0.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_llm_renderer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.7 kB
Release files / flask_llm_renderer-0.1.0.tar.gz
| Download URL | flask_llm_renderer-0.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c645d8b4114a637578a489cf32e7fb3bfbc8ff6b8a395c270cb1fe9e43ec829
|
|
BLAKE2b-256 checksum How to use checksums |
47d90d04ccc46e0f190750db7df2312d67ad986d11e23c37d5a9115f601fce74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Release files / flask_llm_renderer-0.1.0-py3-none-any.whl
| Download URL | flask_llm_renderer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66436b24cac0fad4702ce8615075242c846eb327ca987cf8cc2be5f30766ea78
|
|
BLAKE2b-256 checksum How to use checksums |
d4566d859996e70ce8de0fa19f0b1e7f0da1210e567c5eaeac77c6e80a6260a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Security for flask-llm-renderer 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.