File size: 529 Bytes
bfd5578 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import os
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title="Minimal FastAPI on HF Spaces")
class Item(BaseModel):
text: str
@app.get("/")
def read_root():
return {"hello": "world"}
@app.post("/echo")
def echo(item: Item):
return {"echo": item.text}
# Needed when running in a Python Space: bind to 0.0.0.0 and the provided PORT
if __name__ == "__main__":
import uvicorn
uvicorn.run(
app,
host="0.0.0.0",
port=int(os.environ.get("PORT", 7860)),
)
|