willco-afk commited on
Commit
8f54579
·
verified ·
1 Parent(s): 3640024

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import streamlit as st
2
  from PIL import Image
3
  import torch
4
- from torchvision import transforms
5
- from torchvision.models import resnet50
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 the pre-trained PyTorch model
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}")