realify / main.py
doublelotus's picture
sentence
1ff8dbd
raw
history blame
772 Bytes
import os
from flask import Flask, jsonify, request
from flask_cors import CORS
from transformers import pipeline
# Set the cache directory to a location with write permissions
os.environ['TRANSFORMERS_CACHE'] = './transformers_cache'
os.environ['HF_HOME'] = './transformers_cache'
app = Flask(__name__)
CORS(app)
# Load the sentiment-analysis pipeline from Hugging Face
sentiment_analyzer = pipeline('sentiment-analysis')
@app.route('/')
def hello():
return {"Goes Wrong": "Keeping it real"}
@app.route('/analyze', methods=['GET'])
def analyze():
sentence = request.args.get('sentence', default='hey there', type=str)
result = sentiment_analyzer(sentence)
print(result)
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True)