Download app.py from AstraOS/pyscript: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/AstraOS/pyscript/resolve/main/app.py
- Command line
-
hf download hf://spaces/AstraOS/pyscript/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AstraOS/pyscript/resolve/main/app.py
1.12 kB
| import random | |
| from pathlib import Path | |
| import flask | |
| app = flask.Flask(__name__) | |
| def index(): | |
| return flask.render_template('index.html') | |
| def weather_data(): | |
| data = get_random_report() | |
| return flask.jsonify(data) | |
| def worker(): | |
| js = Path(__file__).parent / 'static' / 'js' / 'serviceWorker.js' | |
| text = js.read_text() | |
| resp = flask.make_response(text) | |
| resp.content_type = 'application/javascript' | |
| resp.headers['Service-Worker-Allowed'] = '/' | |
| return resp | |
| def get_random_report() -> dict: | |
| reports = [ | |
| { | |
| 'report': 'Clear and beautify skies today.', | |
| 'sky': 'sunny', | |
| 'temp': random.randint(65, 88), | |
| }, | |
| { | |
| 'report': 'Cloudy and a bit cool today.', | |
| 'sky': 'cloudy', | |
| 'temp': random.randint(48, 60), | |
| }, | |
| { | |
| 'report': 'Are those icicles falling from the sky? Get inside.', | |
| 'sky': 'rain', | |
| 'temp': random.randint(33, 40), | |
| } | |
| ] | |
| return random.choice(reports) | |