Khaled27 commited on
Commit
2326db6
·
1 Parent(s): 4c7704a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +48 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request
2
+ from transformers import AutoModelForImageClassification
3
+ from transformers import AutoImageProcessor
4
+ from PIL import Image
5
+ import torch
6
+
7
+ app = Flask(__name__)
8
+
9
+ model = AutoModelForImageClassification.from_pretrained(
10
+ '../apiModel/myModel')
11
+ image_processor = AutoImageProcessor.from_pretrained(
12
+ "google/vit-base-patch16-224-in21k")
13
+
14
+
15
+ @app.route('/upload_image', methods=['POST'])
16
+ def upload_image():
17
+ # Get the image file from the request
18
+ image_file = request.files['image']
19
+
20
+ # Save the image file to a desired location on the server
21
+ image_path = "assets/img.jpg"
22
+ image_file.save(image_path)
23
+
24
+ # You can perform additional operations with the image here
25
+ # ...
26
+
27
+ return 'Image uploaded successfully'
28
+
29
+
30
+ @app.route('/get_text', methods=['GET'])
31
+ def get_text():
32
+ image = Image.open('assets/img.jpg')
33
+ inputs = image_processor(image, return_tensors="pt")
34
+
35
+ with torch.no_grad():
36
+ logits = model(**inputs).logits
37
+
38
+ predicted_label = logits.argmax(-1).item()
39
+
40
+ disease = model.config.id2label[predicted_label]
41
+
42
+ return disease
43
+
44
+
45
+ if __name__ == '__app__':
46
+ app.run(host='192.168.1.7', port=5000)
requirements.txt ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ autopep8==1.7.0
2
+ biopython==1.79
3
+ blinker==1.6.2
4
+ certifi==2023.5.7
5
+ charset-normalizer==3.1.0
6
+ click==8.1.3
7
+ colorama==0.4.6
8
+ contourpy==1.0.6
9
+ cycler==0.11.0
10
+ docopt==0.6.2
11
+ filelock==3.12.0
12
+ Flask==2.3.2
13
+ fonttools==4.38.0
14
+ fsspec==2023.5.0
15
+ huggingface-hub==0.14.1
16
+ idna==3.4
17
+ itsdangerous==2.1.2
18
+ Jinja2==3.1.2
19
+ kiwisolver==1.4.4
20
+ MarkupSafe==2.1.2
21
+ matplotlib==3.6.1
22
+ mpmath==1.3.0
23
+ networkx==3.1
24
+ numpy==1.23.4
25
+ opencv-python==4.6.0.66
26
+ packaging==21.3
27
+ pandas==1.5.3
28
+ Pillow==9.3.0
29
+ pipreqs==0.4.13
30
+ pycodestyle==2.9.1
31
+ pyparsing==3.0.9
32
+ python-dateutil==2.8.2
33
+ pytz==2022.7.1
34
+ PyYAML==6.0
35
+ regex==2023.5.5
36
+ requests==2.31.0
37
+ scipy==1.9.3
38
+ six==1.16.0
39
+ sympy==1.12
40
+ tokenizers==0.13.3
41
+ toml==0.10.2
42
+ torch==2.0.1
43
+ tqdm==4.65.0
44
+ transformers==4.29.2
45
+ typing_extensions==4.5.0
46
+ urllib3==2.0.2
47
+ Werkzeug==2.3.4
48
+ yarg==0.1.9