File size: 875 Bytes
30681bf
1dbd4bc
30681bf
1dbd4bc
30681bf
 
1dbd4bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30681bf
 
1dbd4bc
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
27
28
29
30
31
from flask import Flask, request, jsonify
from transformers import pipeline

# Inisialisasi aplikasi Flask
app = Flask(__name__)

# Inisialisasi pipeline untuk sentiment analysis
sentiment_analysis = pipeline("sentiment-analysis", model="w11wo/indonesian-roberta-base-sentiment-classifier")

@app.route('/')
def home():
    return 'API Sentiment Analysis menggunakan w11wo/indonesian-roberta-base-sentiment-classifier'

@app.route('/analyze', methods=['POST'])
def analyze_sentiment():
    try:
        data = request.json
        if 'text' not in data:
            return jsonify({"error": "No text provided"}), 400

        text = data['text']
        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=8080)