Spaces:
Sleeping
Sleeping
Download app/main.py from mars-landing/simple-flask-app: direct link, hf CLI and curl.
- Browser
- Download file 935 Bytes
-
https://huggingface.co/spaces/mars-landing/simple-flask-app/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/mars-landing/simple-flask-app/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/mars-landing/simple-flask-app/resolve/main/app/main.py
935 Bytes
| import os | |
| import base64 | |
| from typing import Union | |
| from os.path import dirname, abspath, join | |
| from fastapi import FastAPI | |
| from fastapi.responses import FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from pydantic import BaseModel | |
| current_dir = dirname(abspath(__file__)) | |
| static_path = join(current_dir, "static") | |
| app = FastAPI() | |
| # app.mount("/ui", StaticFiles(directory=static_path), name="ui") | |
| class Body(BaseModel): | |
| length: Union[int, None] = 20 | |
| # @app.get('/') | |
| # def root(): | |
| # html_path = join(static_path, "index.html") | |
| # return FileResponse(html_path) | |
| def root(): | |
| return "Hello World" | |
| def generate(body: Body): | |
| """ | |
| Generate a pseudo-random token ID of twenty characters by default. Example POST request body: | |
| { | |
| "length": 20 | |
| } | |
| """ | |
| string = base64.b64encode(os.urandom(64))[:body.length].decode('utf-8') | |
| return {'token': string} |