File size: 556 Bytes
a8d3870
 
 
1af149a
a8d3870
1af149a
a8d3870
 
 
1af149a
a8d3870
 
 
34ec8a9
a8d3870
 
 
 
 
669f16a
 
 
 
 
 
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
# 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"}'