Khaled27 commited on
Commit
80125b7
1 Parent(s): 8374c83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -2,6 +2,8 @@ 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__)
@@ -15,36 +17,30 @@ image_processor = AutoImageProcessor.from_pretrained(
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
  @app.route('/', methods=['GET'])
46
  def hi():
47
- return "NAPTAH Mobile Application"
48
 
49
 
50
 
 
2
  from transformers import AutoModelForImageClassification
3
  from transformers import AutoImageProcessor
4
  from PIL import Image
5
+ from io import BytesIO
6
+ import os
7
  import torch
8
 
9
  app = Flask(__name__)
 
17
  @app.route('/upload_image', methods=['POST'])
18
  def upload_image():
19
  # Get the image file from the request
20
+ image_file = request.files['image'].stream
21
+
22
+ # image = Image.open(BytesIO(image_file.read()))
23
+ image = Image.open(image_file)
 
 
 
 
 
 
 
 
 
 
 
24
  inputs = image_processor(image, return_tensors="pt")
25
+
26
  with torch.no_grad():
27
  logits = model(**inputs).logits
28
 
29
  predicted_label = logits.argmax(-1).item()
30
 
31
  disease = model.config.id2label[predicted_label]
32
+
33
+
34
+ # You can perform additional operations with the image here
35
+ # ...
36
 
37
  return disease
38
+
39
 
40
 
41
  @app.route('/', methods=['GET'])
42
  def hi():
43
+ return "Hello world"
44
 
45
 
46