ragilbuaj's picture
fixing
1dbd4bc
raw
history blame contribute delete
875 Bytes
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)