Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the Hugging Face model pipeline
|
5 |
+
model_name = "distilbert-base-uncased" # Change to the model you need
|
6 |
+
nlp = pipeline("text-classification", model=model_name)
|
7 |
+
|
8 |
+
# Create Flask app
|
9 |
+
app = Flask(__name__)
|
10 |
+
|
11 |
+
@app.route("/predict", methods=["POST"])
|
12 |
+
def predict():
|
13 |
+
# Get the data from the request
|
14 |
+
data = request.get_json()
|
15 |
+
text = data.get("text", "")
|
16 |
+
|
17 |
+
if not text:
|
18 |
+
return jsonify({"error": "Text input is required"}), 400
|
19 |
+
|
20 |
+
# Use Hugging Face model for inference
|
21 |
+
result = nlp(text)
|
22 |
+
|
23 |
+
return jsonify({"prediction": result})
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
# Run the app
|
27 |
+
app.run(host="0.0.0.0", port=5000)
|