Skip to content

Conversation

@lk100
Copy link

@lk100 lk100 commented Apr 27, 2025

from flask import Flask, request, jsonify
from transformers import pipeline

Load the Hugging Face model

classifier = pipeline(
"sentiment-analysis",
model="lk1307/love_model",
token="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",
framework="pt" # Force PyTorch
)

Initialize the Flask app

app = Flask(name)

Define a route for sentiment analysis

@app.route("/predict", methods=["POST"])
def predict():
# Get the input text from the JSON request
data = request.get_json()
user_input = data.get("text")

if not user_input:
    return jsonify({"error": "Text is required"}), 400

# Get sentiment analysis result
result = classifier(user_input)

# Return the result as JSON
return jsonify(result)

Run the Flask app

if name == "main":
app.run(debug=True, host="0.0.0.0", port=5000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant