TextModSimple / app.py
DarwinAnim8or's picture
Update app.py
9f33a05
raw history blame
No virus
1.02 kB
# 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(port=7860, debug=True)