xulh
commited on
Commit
·
838d93c
1
Parent(s):
c2dc6ba
代码初始化
Browse files- inference-api/inference.py +17 -0
inference-api/inference.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from fastapi import FastAPI
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
API_URL = "https://api-inference.huggingface.co/models/cardiffnlp/twitter-roberta-base-sentiment-latest"
|
7 |
+
|
8 |
+
|
9 |
+
@app.post("/api-inference")
|
10 |
+
def get_version(body):
|
11 |
+
# payload = {
|
12 |
+
# "inputs": "Today is a great day",
|
13 |
+
# }
|
14 |
+
print("请求参数:", body)
|
15 |
+
headers = {"Authorization": body.token}
|
16 |
+
response = requests.post(API_URL, headers=headers, json=body.payload)
|
17 |
+
return response.json()
|