Spaces:
Running
Running
johnpaulbin
commited on
Commit
·
939c80c
1
Parent(s):
1d6a2f3
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import asyncio
|
3 |
+
from hypercorn.asyncio import serve
|
4 |
+
from hypercorn.config import Config
|
5 |
+
from setfit import SetFitModel
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
|
9 |
+
model = SetFitModel.from_pretrained("johnpaulbin/beanbox-toxic")
|
10 |
+
|
11 |
+
|
12 |
+
@app.route('/infer', methods=['POST'])
|
13 |
+
def translate():
|
14 |
+
data = request.get_json()
|
15 |
+
result = model.predict_proba([data['text']])
|
16 |
+
|
17 |
+
if result[0][0] > result[0][1]:
|
18 |
+
result = "FALSE"
|
19 |
+
else:
|
20 |
+
result = "TRUE"
|
21 |
+
|
22 |
+
return jsonify(result)
|
23 |
+
|
24 |
+
# Define more routes for other operations like download_model, etc.
|
25 |
+
if __name__ == "__main__":
|
26 |
+
config = Config()
|
27 |
+
config.bind = ["0.0.0.0:7860"] # You can specify the host and port here
|
28 |
+
asyncio.run(serve(app, config))
|