Spaces:
Runtime error
Runtime error
Commit
·
749b55f
1
Parent(s):
ca77260
test
Browse files- main.py +8 -30
- requirements.txt +13 -13
main.py
CHANGED
@@ -1,38 +1,16 @@
|
|
1 |
-
import
|
2 |
-
from flask import Flask, jsonify, request
|
3 |
-
from flask_cors import CORS
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
# Set the TRANSFORMERS_CACHE environment variable to a writable directory
|
7 |
-
os.environ['TRANSFORMERS_CACHE'] = '/tmp/huggingface/cache'
|
8 |
-
|
9 |
app = Flask(__name__)
|
10 |
-
CORS(app)
|
11 |
-
|
12 |
-
# Initialize the sentiment analysis pipeline
|
13 |
-
classifier = pipeline("sentiment-analysis")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
return 'hello world'
|
18 |
|
19 |
-
@app.route('/analyze
|
20 |
-
def
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if 'text' not in data:
|
25 |
-
return jsonify({"error": "No text provided"}), 400
|
26 |
-
|
27 |
-
text = data['text']
|
28 |
-
# Run sentiment analysis
|
29 |
-
result = classifier(text)
|
30 |
-
return jsonify(result)
|
31 |
-
except Exception as e:
|
32 |
-
# Log the error message if needed
|
33 |
-
print(f"Error processing the text: {e}")
|
34 |
-
# Return a JSON response with the error message and a 400 Bad Request status
|
35 |
-
return jsonify({"error": "Error processing the text", "details": str(e)}), 400
|
36 |
|
37 |
if __name__ == '__main__':
|
38 |
app.run(debug=True)
|
|
|
1 |
+
from flask import Flask, jsonify
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
|
|
|
|
|
|
4 |
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
# Load the sentiment-analysis pipeline from Hugging Face
|
7 |
+
sentiment_analyzer = pipeline('sentiment-analysis')
|
|
|
8 |
|
9 |
+
@app.route('/analyze', methods=['GET'])
|
10 |
+
def analyze():
|
11 |
+
sentence = "hey there"
|
12 |
+
result = sentiment_analyzer(sentence)
|
13 |
+
return jsonify(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
if __name__ == '__main__':
|
16 |
app.run(debug=True)
|
requirements.txt
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
flask
|
2 |
gunicorn
|
3 |
flask-cors
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
1 |
flask
|
2 |
gunicorn
|
3 |
flask-cors
|
4 |
+
numpy
|
5 |
+
opencv-python
|
6 |
+
Pillow
|
7 |
+
requests
|
8 |
+
git+https://github.com/facebookresearch/segment-anything.git
|
9 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
10 |
+
torch
|
11 |
+
torchvision
|
12 |
+
matplotlib # Required for image processing and mask visualization
|
13 |
+
onnxruntime
|
14 |
+
onnx
|
15 |
+
pycocotools
|
16 |
+
transformers
|