Download app.py from jameshns/dk: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/spaces/jameshns/dk/resolve/main/app.py
- Command line
-
hf download hf://spaces/jameshns/dk/app.py
-
curl -L -o app.py https://huggingface.co/spaces/jameshns/dk/resolve/main/app.py
2.15 kB
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse | |
| app = FastAPI() | |
| state = [-1,-1,-1,-1,-1,-1,-1,-1,-1] | |
| step = '🐱' | |
| def greet_json(): | |
| # return {"Hello": "World!"} | |
| # return state | |
| html_content = """ | |
| <html> | |
| <head> | |
| <title>Some HTML in here</title> | |
| <style> | |
| .char{ | |
| padding:20px; | |
| background-color:green; | |
| margin-left:55px; | |
| margin-right:55px; | |
| cursor:pointer; | |
| } | |
| .char:even { | |
| background-color:yellow; | |
| } | |
| </style> | |
| <script | |
| src="https://code.jquery.com/jquery-3.7.1.min.js" | |
| integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" | |
| crossorigin="anonymous"></script> | |
| </head> | |
| <body> | |
| <script> | |
| function go(i){ | |
| $.get('/turn/'+i); | |
| document.location.reload(); | |
| } | |
| </script> | |
| """ | |
| html_content += 'сейчас ходит: ' + step + '<br><br>' | |
| for i in range(9): | |
| if state[i] == -1: | |
| char = '_' | |
| elif state[i] == 1: | |
| char = '🐭' | |
| elif state[i] == 0: | |
| char = '🐱' | |
| if i in [0,3,6]: | |
| html_content += '<br><br><br><br>' | |
| html_content += '<span class="char"><span onclick="go('+str(i)+')">' + char + '</span></span>' | |
| html_content += '<br><br><br><br><br><a href="/reset">reset</a>' | |
| html_content += """ | |
| </body> | |
| </html> | |
| """ | |
| return HTMLResponse(content=html_content, status_code=200) | |
| def change_step(): | |
| global step | |
| print(step) | |
| if step == '🐱': | |
| step = '🐭' | |
| elif step == '🐭': | |
| step = '🐱' | |
| def turn(pos): | |
| global state | |
| if state[int(pos)] == '-1': | |
| state[int(pos)] = step | |
| else: | |
| state[int(pos)] = int(not state[int(pos)]) | |
| change_step() | |
| def reset(): | |
| global state | |
| state = [-1,-1,-1,-1,-1,-1,-1,-1,-1] |