DarwinAnim8or commited on
Commit
dc6d361
·
1 Parent(s): 8c30f0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -11,11 +11,13 @@ app = Flask(__name__)
11
  # Create a text classification pipeline using a pretrained model
12
  classifier = pipeline("text-classification", model="KoalaAI/Text-Moderation")
13
 
14
- # Define a route for the home page
15
  @app.route("/")
16
  def home():
17
- # Render a template with a web form
18
- return render_template("index.html")
 
 
 
19
 
20
  # Define a route for the classification result
21
  @app.route("/classify", methods=["POST"])
@@ -27,8 +29,16 @@ def classify():
27
  # Extract the label and the score
28
  label = result["label"]
29
  score = result["score"]
30
- # Render a template with the classification result
31
- return render_template("result.html", text=text, label=label, score=score)
 
 
 
 
 
 
 
 
32
 
33
  # Run the app in debug mode
34
  if __name__ == "__main__":
 
11
  # Create a text classification pipeline using a pretrained model
12
  classifier = pipeline("text-classification", model="KoalaAI/Text-Moderation")
13
 
 
14
  @app.route("/")
15
  def home():
16
+ # Return a simple HTML page
17
+ return "<html><head><title>Text Classification</title></head><body><h1>Text Classification with Huggingface</h1></body></html>"
18
+
19
+ # Import the xml module
20
+ import xml.etree.ElementTree as ET
21
 
22
  # Define a route for the classification result
23
  @app.route("/classify", methods=["POST"])
 
29
  # Extract the label and the score
30
  label = result["label"]
31
  score = result["score"]
32
+ # Create a root element for the XML response
33
+ root = ET.Element("result")
34
+ # Add sub-elements for the label and the score
35
+ ET.SubElement(root, "label").text = label
36
+ ET.SubElement(root, "score").text = str(score)
37
+ # Convert the XML element to a byte string
38
+ xml_string = ET.tostring(root)
39
+ # Return the XML string as the response with the appropriate mimetype
40
+ return app.response_class(xml_string, mimetype="application/xml")
41
+
42
 
43
  # Run the app in debug mode
44
  if __name__ == "__main__":