Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
-
|
| 5 |
-
from torchvision
|
| 6 |
import torch.nn.functional as F
|
| 7 |
|
| 8 |
# Set up a title for the app
|
| 9 |
-
st.title("Image Recognition App")
|
| 10 |
|
| 11 |
-
# Load
|
| 12 |
-
model = resnet50(pretrained=True)
|
| 13 |
model.eval() # Set the model to evaluation mode
|
| 14 |
|
| 15 |
# Upload an image
|
|
@@ -35,5 +35,8 @@ if uploaded_file is not None:
|
|
| 35 |
outputs = model(image_tensor)
|
| 36 |
probabilities = F.softmax(outputs[0], dim=0)
|
| 37 |
top3_prob, top3_classes = torch.topk(probabilities, 3)
|
|
|
|
|
|
|
|
|
|
| 38 |
for i in range(3):
|
| 39 |
st.write(f"Label: {top3_classes[i].item()}, Confidence: {top3_prob[i].item():.2f}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
+
import torchvision.transforms as transforms
|
| 5 |
+
from torchvision import models
|
| 6 |
import torch.nn.functional as F
|
| 7 |
|
| 8 |
# Set up a title for the app
|
| 9 |
+
st.title("Simple Image Recognition App")
|
| 10 |
|
| 11 |
+
# Load a pre-trained model from torchvision (e.g., ResNet50)
|
| 12 |
+
model = models.resnet50(pretrained=True)
|
| 13 |
model.eval() # Set the model to evaluation mode
|
| 14 |
|
| 15 |
# Upload an image
|
|
|
|
| 35 |
outputs = model(image_tensor)
|
| 36 |
probabilities = F.softmax(outputs[0], dim=0)
|
| 37 |
top3_prob, top3_classes = torch.topk(probabilities, 3)
|
| 38 |
+
|
| 39 |
+
# Display the top 3 predictions
|
| 40 |
+
st.write("Predictions:")
|
| 41 |
for i in range(3):
|
| 42 |
st.write(f"Label: {top3_classes[i].item()}, Confidence: {top3_prob[i].item():.2f}")
|