pushpinder06 commited on
Commit
85e829a
·
verified ·
1 Parent(s): 1d2e0b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -4,8 +4,8 @@ from tensorflow.keras.preprocessing.image import img_to_array
4
  import numpy as np
5
  from PIL import Image
6
 
7
- # Load the trained model
8
- model = load_model("waste_classification(Mobilenetv2).h5")
9
  class_names = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
10
 
11
  # Prediction function
@@ -20,12 +20,11 @@ def predict_from_webcam(image):
20
 
21
  return f"{predicted_class} ({confidence*100:.1f}%)"
22
 
23
- # Gradio interface with webcam input
24
  gr.Interface(
25
  fn=predict_from_webcam,
26
- inputs=gr.Image(source="webcam", tool=None, type="pil"),
27
  outputs="text",
28
- live=True,
29
  title="Live Waste Classifier",
30
- description="Show waste to your webcam. This app predicts if it's paper, glass, plastic, etc."
31
  ).launch()
 
4
  import numpy as np
5
  from PIL import Image
6
 
7
+ # Load model
8
+ model = load_model("waste_classifier_model.h5")
9
  class_names = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
10
 
11
  # Prediction function
 
20
 
21
  return f"{predicted_class} ({confidence*100:.1f}%)"
22
 
23
+ # Use gr.Camera() for webcam input (Gradio 4.x)
24
  gr.Interface(
25
  fn=predict_from_webcam,
26
+ inputs=gr.Camera(type="pil"), # webcam input as PIL image
27
  outputs="text",
 
28
  title="Live Waste Classifier",
29
+ description="Point your webcam at waste material. The model will classify it live."
30
  ).launch()