Spaces:
Runtime error
Runtime error
File size: 772 Bytes
f48b8b0 1ff8dbd 7f6bab7 5a42448 e9cd1d1 f48b8b0 d6e00ed f48b8b0 e9cd1d1 7f6bab7 5a42448 749b55f e9cd1d1 7f6bab7 749b55f 1ff8dbd 749b55f 726d8ee 749b55f 5a42448 1ff8dbd e9cd1d1 |
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 |
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)
|