Spaces:
Sleeping
Sleeping
Commit
·
d5bc363
1
Parent(s):
1907678
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from flask import Flask, request
|
|
| 2 |
from transformers import AutoModelForImageClassification
|
| 3 |
from transformers import AutoImageProcessor
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
import os
|
| 6 |
import torch
|
| 7 |
|
|
@@ -20,27 +21,32 @@ def upload_image():
|
|
| 20 |
|
| 21 |
# Save the image file to a desired location on the server
|
| 22 |
# image_path = "assets/"
|
| 23 |
-
image_file.save(os.path.join('/', 'img.jpg'))
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# ...
|
| 27 |
-
|
| 28 |
-
return "Image uploaded successfully"
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
@app.route('/get_text', methods=['GET'])
|
| 32 |
-
def get_text():
|
| 33 |
-
image = Image.open('/img.jpg')
|
| 34 |
inputs = image_processor(image, return_tensors="pt")
|
| 35 |
-
|
| 36 |
with torch.no_grad():
|
| 37 |
logits = model(**inputs).logits
|
| 38 |
|
| 39 |
predicted_label = logits.argmax(-1).item()
|
| 40 |
|
| 41 |
disease = model.config.id2label[predicted_label]
|
|
|
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
return disease
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
@app.route('/', methods=['GET'])
|
|
|
|
| 2 |
from transformers import AutoModelForImageClassification
|
| 3 |
from transformers import AutoImageProcessor
|
| 4 |
from PIL import Image
|
| 5 |
+
import BytesIO
|
| 6 |
import os
|
| 7 |
import torch
|
| 8 |
|
|
|
|
| 21 |
|
| 22 |
# Save the image file to a desired location on the server
|
| 23 |
# image_path = "assets/"
|
| 24 |
+
# image_file.save(os.path.join('/', 'img.jpg'))
|
| 25 |
+
|
| 26 |
+
image = Image.open(BytesIO(image_file))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
inputs = image_processor(image, return_tensors="pt")
|
| 28 |
+
|
| 29 |
with torch.no_grad():
|
| 30 |
logits = model(**inputs).logits
|
| 31 |
|
| 32 |
predicted_label = logits.argmax(-1).item()
|
| 33 |
|
| 34 |
disease = model.config.id2label[predicted_label]
|
| 35 |
+
|
| 36 |
|
| 37 |
+
# You can perform additional operations with the image here
|
| 38 |
+
# ...
|
| 39 |
+
|
| 40 |
+
# return "Image uploaded successfully"
|
| 41 |
return disease
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@app.route('/get_text', methods=['GET'])
|
| 46 |
+
def get_text():
|
| 47 |
+
# image = Image.open('/img.jpg')
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
|
| 51 |
|
| 52 |
@app.route('/', methods=['GET'])
|