from fastapi import FastAPI, Form from fastapi.responses import HTMLResponse, StreamingResponse import asyncio import random import string import uvicorn app = FastAPI() @app.head("/") @app.get("/", response_class=HTMLResponse) async def get_form(): return """ URL Input
""" @app.post("/submit") async def submit_url(url: str = Form(...), filename: str = Form(None)): if not filename: filename = url.split("/")[-1] async def generate_html(): yield f'

Filename: {filename}

Lorem Ipsum Text:

' lorem_text = ''.join(random.choices(string.ascii_letters + string.digits + ' ', k=1000)) for char in lorem_text: await asyncio.sleep(0.01) # 10ms delay yield char headers = { "Content-Type": "text/html", "Transfer-Encoding": "chunked", "Cache-Control": "no-cache", "X-Accel-Buffering": "no" } return StreamingResponse(generate_html(), headers=headers) if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)