Fastapitest / app.py
hsuwill000's picture
Update app.py
669f16a verified
raw
history blame contribute delete
556 Bytes
# app.py
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
# 定義輸入/輸出資料格式
class Item(BaseModel):
text: str
@app.get("/")
def root():
return {"message": "Hello from FastAPI on HF Space!"}
@app.post("/predict")
def predict(item: Item):
# 模擬一個簡單推論邏輯
result = item.text.upper()
return {"input": item.text, "result": result}
#sample
#!curl -X POST https://hsuwill000-fastapitest.hf.space/predict \
# -H "Content-Type: application/json" \
# -d '{"text":"hello world2"}'