File size: 732 Bytes
939c80c
 
 
 
 
 
 
 
ff8641c
939c80c
 
 
 
 
 
 
 
2a5bacf
939c80c
2a5bacf
939c80c
d9ff418
939c80c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from flask import Flask, request, jsonify
import asyncio
from hypercorn.asyncio import serve
from hypercorn.config import Config
from setfit import SetFitModel

app = Flask(__name__)

model = SetFitModel.from_pretrained("johnpaulbin/toxic-gte-small-3")


@app.route('/infer', methods=['POST'])
def translate():
    data = request.get_json()
    result = model.predict_proba([data['text']])

    if result[0][0] > result[0][1]:
        result = "false"
    else:
        result = "true"

    return result

# Define more routes for other operations like download_model, etc.
if __name__ == "__main__":
   config = Config()
   config.bind = ["0.0.0.0:7860"]  # You can specify the host and port here
   asyncio.run(serve(app, config))