from fastapi import FastAPI from fastapi.responses import HTMLResponse, JSONResponse import requests import uvicorn # Initialize FastAPI app app = FastAPI() # API endpoint for getting cryptocurrency prices from CoinGecko API_URL = 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,dogecoin&vs_currencies=usd' # HTML template with HTMX integration HTML_TEMPLATE = """ Crypto Price Dashboard

Cryptocurrency Prices

Loading...
""" @app.get("/", response_class=HTMLResponse) def read_root(): return HTML_TEMPLATE @app.get("/api/prices", response_class=JSONResponse) def get_prices(): response = requests.get(API_URL) response.raise_for_status() return response.json() if __name__ == "__main__": # Run with: uvicorn this_file_name:app --host 0.0.0.0 --port 7860 --reload uvicorn.run("this_file_name:app", host="0.0.0.0", port=7860, reload=True)