File size: 540 Bytes
61c449a
80edbd1
 
def877f
 
80edbd1
def877f
 
80edbd1
 
def877f
80edbd1
 
 
 
61c449a
 
e6dcb5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline

app = FastAPI()
moderate_pipe = pipeline("text-classification", model="KoalaAI/Text-Moderation")

class TextInput(BaseModel):
    text: str

@app.post("/moderate")
async def moderate_text(input: TextInput):
    results = moderate_pipe(input.text)
    return {r["label"]: r["score"] for r in results}

# Gradio interface to expose the model API via a Space
gr.Interface(fn=moderate_text, inputs="text", outputs="json").launch()