Spaces:
Running
Running
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") | |
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)) |