Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
-
|
5 |
-
|
6 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
7 |
|
8 |
extractor = AutoFeatureExtractor.from_pretrained("Amite5h/convnext-tiny-finetuned-eurosat")
|
@@ -11,8 +10,6 @@ model = AutoModelForImageClassification.from_pretrained("Amite5h/convnext-tiny-f
|
|
11 |
|
12 |
|
13 |
|
14 |
-
#pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
|
15 |
-
|
16 |
st.title("EuroSAT Detection")
|
17 |
|
18 |
file_name = st.file_uploader("Upload a hot dog candidate image")
|
@@ -27,9 +24,21 @@ if file_name is not None:
|
|
27 |
# Convert grayscale image to RGB format
|
28 |
image_tensor = extractor(images=image, return_tensors="pt")["pixel_values"]
|
29 |
predictions = model(image_tensor)
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
col2.header("Probabilities")
|
32 |
-
col2.subheader(
|
33 |
|
34 |
# col2.header("Probabilities")
|
35 |
# for p in predictions:
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
+
import json
|
|
|
5 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
6 |
|
7 |
extractor = AutoFeatureExtractor.from_pretrained("Amite5h/convnext-tiny-finetuned-eurosat")
|
|
|
10 |
|
11 |
|
12 |
|
|
|
|
|
13 |
st.title("EuroSAT Detection")
|
14 |
|
15 |
file_name = st.file_uploader("Upload a hot dog candidate image")
|
|
|
24 |
# Convert grayscale image to RGB format
|
25 |
image_tensor = extractor(images=image, return_tensors="pt")["pixel_values"]
|
26 |
predictions = model(image_tensor)
|
27 |
+
|
28 |
+
predicted_probabilities = torch.softmax(outputs.logits, dim=1)[0]
|
29 |
+
predicted_labels = model.config.id2label
|
30 |
+
|
31 |
+
# Create a dictionary of labels and probabilities
|
32 |
+
label_probabilities = {
|
33 |
+
predicted_labels[i]: predicted_probabilities[i].item() for i in range(len(predicted_labels))
|
34 |
+
}
|
35 |
+
|
36 |
+
# Convert the output to JSON string
|
37 |
+
json_output = json.dumps(label_probabilities)
|
38 |
+
|
39 |
+
#predicted_class = torch.argmax(predictions.logits, dim=1)
|
40 |
col2.header("Probabilities")
|
41 |
+
col2.subheader(json_output)
|
42 |
|
43 |
# col2.header("Probabilities")
|
44 |
# for p in predictions:
|