mgbam's picture
Create app.py
8a252de verified
raw
history blame
678 Bytes
from flask import Flask, jsonify, request
import requests
from transformers import pipeline
app = Flask(__name__)
# Initialize sentiment analysis pipeline from Hugging Face
sentiment_analysis = pipeline("sentiment-analysis")
# Example endpoint for sentiment analysis using Hugging Face Transformers
@app.route('/api/sentiment', methods=['POST'])
def analyze_sentiment():
try:
text = request.json['text']
# Perform sentiment analysis
result = sentiment_analysis(text)
return jsonify(result), 200
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)