Turkeyengineer commited on
Commit
282d567
Β·
verified Β·
1 Parent(s): 4ae44d5

Upload 3 files

Browse files
Files changed (3) hide show
  1. .well-known/openapi.yaml +33 -0
  2. app.py +20 -0
  3. 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-pos.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-pos", tokenizer=AutoTokenizer.from_pretrained("ckiplab/bert-base-chinese-pos"), 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