FastAPI / app.py
umair894's picture
Create app.py
bfd5578 verified
raw
history blame contribute delete
529 Bytes
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)),
)