Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- .well-known/openapi.yaml +33 -0
- app.py +20 -0
- requirements.txt +5 -0
.well-known/openapi.yaml
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openapi: 3.0.1
|
2 |
+
info:
|
3 |
+
title: 實體辨識 API
|
4 |
+
description: 提供 實體辨識 任務分析
|
5 |
+
version: "1.0.0"
|
6 |
+
servers:
|
7 |
+
- url: https://turkeyengineer-ckip-ner.hf.space
|
8 |
+
paths:
|
9 |
+
/analyze:
|
10 |
+
post:
|
11 |
+
summary: 分析輸入句子
|
12 |
+
operationId: analyze
|
13 |
+
requestBody:
|
14 |
+
required: true
|
15 |
+
content:
|
16 |
+
application/json:
|
17 |
+
schema:
|
18 |
+
type: object
|
19 |
+
properties:
|
20 |
+
sentence:
|
21 |
+
type: string
|
22 |
+
example: 這是一個測試句子。
|
23 |
+
responses:
|
24 |
+
'200':
|
25 |
+
description: 成功回傳分析結果
|
26 |
+
content:
|
27 |
+
application/json:
|
28 |
+
schema:
|
29 |
+
type: object
|
30 |
+
properties:
|
31 |
+
result:
|
32 |
+
type: string
|
33 |
+
example: 分析結果
|
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastapi import FastAPI, Request
|
3 |
+
from fastapi.responses import JSONResponse
|
4 |
+
from transformers import pipeline, AutoTokenizer
|
5 |
+
|
6 |
+
model = pipeline("token-classification", model="ckiplab/bert-base-chinese-ner", tokenizer=AutoTokenizer.from_pretrained("ckiplab/bert-base-chinese-ner"), aggregation_strategy="simple")
|
7 |
+
|
8 |
+
def analyze(sentence: str):
|
9 |
+
result = model(sentence)
|
10 |
+
return
|
11 |
+
|
12 |
+
demo = gr.Interface(fn=analyze, inputs="text", outputs="text", title="實體辨識")
|
13 |
+
|
14 |
+
app = FastAPI()
|
15 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
16 |
+
|
17 |
+
@app.post("/analyze")
|
18 |
+
async def api_analyze(request: Request):
|
19 |
+
payload = await request.json()
|
20 |
+
return JSONResponse(content={"result": analyze(payload.get("sentence", ""))})
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
fastapi
|
5 |
+
uvicorn
|