geethareddy's picture
Create app.py
a65ab2b verified
raw
history blame
729 Bytes
from flask import Flask, request, jsonify
from transformers import pipeline
# Initialize the Hugging Face model pipeline
model_name = "distilbert-base-uncased" # Change to the model you need
nlp = pipeline("text-classification", model=model_name)
# Create Flask app
app = Flask(__name__)
@app.route("/predict", methods=["POST"])
def predict():
# Get the data from the request
data = request.get_json()
text = data.get("text", "")
if not text:
return jsonify({"error": "Text input is required"}), 400
# Use Hugging Face model for inference
result = nlp(text)
return jsonify({"prediction": result})
if __name__ == "__main__":
# Run the app
app.run(host="0.0.0.0", port=5000)