ConradLax commited on
Commit
057478d
·
1 Parent(s): 0458545

feat: sentiment-analysis

Browse files
Files changed (2) hide show
  1. main.py +30 -1
  2. requirements.txt +53 -1
main.py CHANGED
@@ -5,4 +5,33 @@ app = Flask(__name__)
5
 
6
  @app.route('/')
7
  def index():
8
- return {'message': 'successfully deployed'}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  @app.route('/')
7
  def index():
8
+ return {'message': 'successfully deployed'}
9
+
10
+ import torch
11
+ from transformers import pipeline
12
+ from transformers import DonutProcessor, VisionEncoderDecoderModel
13
+ from datasets import load_dataset
14
+ import os
15
+ from PIL import Image
16
+
17
+
18
+
19
+ classifier_doctype_processor = DonutProcessor.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
20
+ classifier_doctype_model = VisionEncoderDecoderModel.from_pretrained("calumpianojericho/donutclassifier_acctdocs_by_doctype")
21
+
22
+ # Load the sentiment analysis model
23
+ sentiment_analysis = pipeline("sentiment-analysis")
24
+
25
+ @app.route("/analyze", methods=["POST"])
26
+ def analyze_sentiment():
27
+ try:
28
+ data = request.json
29
+ text = data["text"]
30
+
31
+ # Perform sentiment analysis
32
+ result = sentiment_analysis(text)
33
+
34
+ return jsonify({"sentiment": result[0]["label"], "score": result[0]["score"]})
35
+
36
+ except Exception as e:
37
+ return jsonify({"error": str(e)}), 500
requirements.txt CHANGED
@@ -1,2 +1,54 @@
1
  flask
2
- gunicorn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  flask
2
+ gunicorn
3
+ aiohttp==3.9.1
4
+ aiosignal==1.3.1
5
+ altgraph==0.17.4
6
+ async-timeout==4.0.3
7
+ attrs==23.1.0
8
+ certifi==2023.11.17
9
+ charset-normalizer==3.3.2
10
+ colorama==0.4.6
11
+ datasets==2.15.0
12
+ dill==0.3.7
13
+ filelock==3.13.1
14
+ frozenlist==1.4.0
15
+ fsspec==2023.10.0
16
+ huggingface-hub==0.19.4
17
+ idna==3.6
18
+ importlib-metadata==7.0.0
19
+ Jinja2==3.1.2
20
+ MarkupSafe==2.1.3
21
+ mpmath==1.3.0
22
+ multidict==6.0.4
23
+ multiprocess==0.70.15
24
+ networkx==3.1
25
+ numpy==1.24.4
26
+ packaging==23.2
27
+ pandas==2.0.3
28
+ pefile==2023.2.7
29
+ Pillow==10.1.0
30
+ protobuf==4.25.1
31
+ pyarrow==14.0.1
32
+ pyarrow-hotfix==0.6
33
+ pyinstaller==6.3.0
34
+ pyinstaller-hooks-contrib==2023.10
35
+ python-dateutil==2.8.2
36
+ pytz==2023.3.post1
37
+ pywin32-ctypes==0.2.2
38
+ PyYAML==6.0.1
39
+ regex==2023.10.3
40
+ requests==2.31.0
41
+ safetensors==0.4.1
42
+ sentencepiece==0.1.99
43
+ six==1.16.0
44
+ sympy==1.12
45
+ tokenizers==0.15.0
46
+ torch==2.1.1
47
+ tqdm==4.66.1
48
+ transformers==4.36.0
49
+ typing_extensions==4.9.0
50
+ tzdata==2023.3
51
+ urllib3==2.1.0
52
+ xxhash==3.4.1
53
+ yarl==1.9.4
54
+ zipp==3.17.0