Turkeyengineer commited on
Commit
d13114d
·
verified ·
1 Parent(s): 17de582

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,15 +1,14 @@
1
- import gradio as gr
 
2
 
3
- def segment(text):
4
- return " / ".join(list(text))
5
 
6
- demo = gr.Interface(
7
- fn=segment,
8
- inputs=gr.Textbox(lines=2, placeholder="輸入一段中文..."),
9
- outputs="text",
10
- title="中文斷詞模擬器",
11
- description="這是一個簡易的中文斷詞工具,未來將整合 CKIP 模型。",
12
- api_name="run_predict" # ✅ 設在這裡
13
- )
14
-
15
- demo.launch()
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import JSONResponse
3
 
4
+ app = FastAPI()
 
5
 
6
+ @app.post("/run_predict")
7
+ async def run_predict(request: Request):
8
+ try:
9
+ body = await request.json()
10
+ sentences = body.get("data", [])
11
+ results = [" / ".join(list(s)) for s in sentences]
12
+ return JSONResponse(content={"data": results})
13
+ except Exception as e:
14
+ return JSONResponse(content={"error": str(e)}, status_code=500)