Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	File size: 1,005 Bytes
			
			631856f  | 
								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 29 30 31 32  | 
								# Import the necessary modules
from flask import Flask, request, render_template
from transformers import pipeline
# Create a Flask app
app = Flask(__name__)
# Create a text classification pipeline using a pretrained model
classifier = pipeline("text-classification", model="KoalaAI/Text-Moderation")
# Define a route for the home page
@app.route("/")
def home():
    # Render a template with a web form
    return render_template("index.html")
# Define a route for the classification result
@app.route("/classify", methods=["POST"])
def classify():
    # Get the text from the web form
    text = request.form.get("text")
    # Perform the text classification
    result = classifier(text)[0]
    # Extract the label and the score
    label = result["label"]
    score = result["score"]
    # Render a template with the classification result
    return render_template("result.html", text=text, label=label, score=score)
# Run the app in debug mode
if __name__ == "__main__":
    app.run(debug=True) |