File size: 678 Bytes
8a252de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)