Download app.py from cloudfom/it: direct link, hf CLI and curl.
- Browser
- Download file 774 Bytes
-
https://huggingface.co/spaces/cloudfom/it/resolve/main/app.py
- Command line
-
hf download hf://spaces/cloudfom/it/app.py
-
curl -L -o app.py https://huggingface.co/spaces/cloudfom/it/resolve/main/app.py
774 Bytes
| from fastapi import FastAPI, UploadFile, Form | |
| from fastapi.responses import FileResponse | |
| import os, shutil | |
| from image.qr import generate_qr | |
| from image.watermark import add_qr_to_background | |
| app = FastAPI() | |
| TEMP_DIR = "temp" | |
| os.makedirs(TEMP_DIR, exist_ok=True) | |
| async def create_background( | |
| file: UploadFile, | |
| premium: bool = Form(False) | |
| ): | |
| input_path = f"{TEMP_DIR}/input.png" | |
| output_path = f"{TEMP_DIR}/output.png" | |
| with open(input_path, "wb") as f: | |
| f.write(await file.read()) | |
| if premium: | |
| shutil.copy(input_path, output_path) | |
| else: | |
| qr = generate_qr("https://cloudfom.org") | |
| add_qr_to_background(input_path, output_path, qr) | |
| return FileResponse(output_path, media_type="image/png") | |