DarwinAnim8or commited on
Commit
631856f
1 Parent(s): 86ffda0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import the necessary modules
2
+ from flask import Flask, request, render_template
3
+ from transformers import pipeline
4
+
5
+ # Create a Flask app
6
+ app = Flask(__name__)
7
+
8
+ # Create a text classification pipeline using a pretrained model
9
+ classifier = pipeline("text-classification", model="KoalaAI/Text-Moderation")
10
+
11
+ # Define a route for the home page
12
+ @app.route("/")
13
+ def home():
14
+ # Render a template with a web form
15
+ return render_template("index.html")
16
+
17
+ # Define a route for the classification result
18
+ @app.route("/classify", methods=["POST"])
19
+ def classify():
20
+ # Get the text from the web form
21
+ text = request.form.get("text")
22
+ # Perform the text classification
23
+ result = classifier(text)[0]
24
+ # Extract the label and the score
25
+ label = result["label"]
26
+ score = result["score"]
27
+ # Render a template with the classification result
28
+ return render_template("result.html", text=text, label=label, score=score)
29
+
30
+ # Run the app in debug mode
31
+ if __name__ == "__main__":
32
+ app.run(debug=True)