pradanaadn commited on
Commit
5c80b12
·
1 Parent(s): 869b2b3

chore: remove hsare

Browse files
Files changed (1) hide show
  1. main.py +6 -11
main.py CHANGED
@@ -5,7 +5,7 @@ from huggingface_hub import PyTorchModelHubMixin
5
  from torchvision.models import mobilenet_v3_large
6
  from torchvision.transforms import v2
7
  from PIL import Image
8
- import os
9
 
10
 
11
  class TrashMobileNet(nn.Module, PyTorchModelHubMixin):
@@ -24,12 +24,10 @@ class TrashMobileNet(nn.Module, PyTorchModelHubMixin):
24
  return x
25
 
26
 
27
- # Load the model from Hugging Face Hub
28
  model_name = "pradanaadn/trash-clasification"
29
  model = TrashMobileNet.from_pretrained(model_name)
30
  model.eval()
31
 
32
- # Define the image transformations
33
  transform = v2.Compose([
34
  v2.Resize((224, 224)),
35
  v2.ToImage(),
@@ -38,20 +36,18 @@ transform = v2.Compose([
38
 
39
 
40
  def predict(image):
41
- """
42
- Prediction function that takes a Gradio image input and returns class probabilities
43
- """
44
  labels = ["cardboard", "glass", "metal", "paper", "plastic", "trash"]
45
 
46
- # Convert Gradio image to PIL Image if it's not already
47
  if not isinstance(image, Image.Image):
48
  image = Image.fromarray(image)
49
 
50
- # Apply transformations and add batch dimension
51
  image_tensor = transform(image)
52
  image_tensor = image_tensor.unsqueeze(0)
53
 
54
- # Get model predictions
55
  with torch.no_grad():
56
  outputs = model(image_tensor)
57
  probabilities = torch.nn.functional.softmax(outputs, dim=1)
@@ -63,7 +59,6 @@ def predict(image):
63
 
64
 
65
 
66
- # Create example images if they don't exist (you would need to provide these images)
67
  examples = [
68
  ["examples/cardbox.jpeg", "A cardboard box"],
69
  ["examples/glass.jpeg", "A glass bottle"],
@@ -106,4 +101,4 @@ with gr.Blocks() as iface:
106
 
107
 
108
  # Launch the interface
109
- iface.launch(share=True)
 
5
  from torchvision.models import mobilenet_v3_large
6
  from torchvision.transforms import v2
7
  from PIL import Image
8
+
9
 
10
 
11
  class TrashMobileNet(nn.Module, PyTorchModelHubMixin):
 
24
  return x
25
 
26
 
 
27
  model_name = "pradanaadn/trash-clasification"
28
  model = TrashMobileNet.from_pretrained(model_name)
29
  model.eval()
30
 
 
31
  transform = v2.Compose([
32
  v2.Resize((224, 224)),
33
  v2.ToImage(),
 
36
 
37
 
38
  def predict(image):
39
+
 
 
40
  labels = ["cardboard", "glass", "metal", "paper", "plastic", "trash"]
41
 
42
+
43
  if not isinstance(image, Image.Image):
44
  image = Image.fromarray(image)
45
 
46
+
47
  image_tensor = transform(image)
48
  image_tensor = image_tensor.unsqueeze(0)
49
 
50
+
51
  with torch.no_grad():
52
  outputs = model(image_tensor)
53
  probabilities = torch.nn.functional.softmax(outputs, dim=1)
 
59
 
60
 
61
 
 
62
  examples = [
63
  ["examples/cardbox.jpeg", "A cardboard box"],
64
  ["examples/glass.jpeg", "A glass bottle"],
 
101
 
102
 
103
  # Launch the interface
104
+ iface.launch()