# 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"}'