CoolFace
Apppublic

umair894/FastAPI

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1import os2from fastapi import FastAPI3from pydantic import BaseModel4 5app = FastAPI(title="Minimal FastAPI on HF Spaces")6 7class Item(BaseModel):8    text: str9 10@app.get("/")11def read_root():12    return {"hello": "world"}13 14@app.post("/echo")15def echo(item: Item):16    return {"echo": item.text}17 18# Needed when running in a Python Space: bind to 0.0.0.0 and the provided PORT19if __name__ == "__main__":20    import uvicorn21    uvicorn.run(22        app,23        host="0.0.0.0",24        port=int(os.environ.get("PORT", 7860)),25    )26