Spaces:
Runtime error
Runtime error
| # 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 | |
| def home(): | |
| # Render a template with a web form | |
| return render_template("index.html") | |
| # Define a route for the classification result | |
| 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) |