tommy24 commited on
Commit
3c31877
·
1 Parent(s): 381e9cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -24,8 +24,8 @@ data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
24
  with open("labels.txt", "r") as file:
25
  labels = file.read().splitlines()
26
 
27
- def classify(image_path):
28
- try:
29
  output = [] # Create an empty list for output
30
  image_data = np.array(image_path)
31
  image_data = cv.resize(image_data, (224, 224))
@@ -46,7 +46,7 @@ def classify(image_path):
46
 
47
  for i, label in enumerate(labels):
48
  prediction_value = float(prediction[0][i])
49
- rounded_value = round(prediction_value, 2)
50
  print(f'{label}: {rounded_value}')
51
 
52
  if prediction_value > max_prediction_value:
@@ -78,13 +78,12 @@ def classify(image_path):
78
  output.append({"type": max_label, "prediction_value": round(max_prediction_value, 2), "content": reply})
79
 
80
  return output # Return the populated output list
81
-
82
- except Exception as e:
83
- return f"An error occurred: {e}"
84
 
85
  iface = gr.Interface(
86
  fn=classify,
87
- inputs=gr.inputs.Image(),
88
  outputs=gr.outputs.JSON(), # Output as JSON
89
  title="Waste Classifier",
90
  description="Upload an image to classify and get disposal instructions."
 
24
  with open("labels.txt", "r") as file:
25
  labels = file.read().splitlines()
26
 
27
+ def classify(image_path, text_input):
28
+ if text_input == code:
29
  output = [] # Create an empty list for output
30
  image_data = np.array(image_path)
31
  image_data = cv.resize(image_data, (224, 224))
 
46
 
47
  for i, label in enumerate(labels):
48
  prediction_value = float(prediction[0][i])
49
+ rounded_value = round prediction_value, 2)
50
  print(f'{label}: {rounded_value}')
51
 
52
  if prediction_value > max_prediction_value:
 
78
  output.append({"type": max_label, "prediction_value": round(max_prediction_value, 2), "content": reply})
79
 
80
  return output # Return the populated output list
81
+ else:
82
+ return "Unauthorized"
 
83
 
84
  iface = gr.Interface(
85
  fn=classify,
86
+ inputs=[gr.inputs.Image(), "text"],
87
  outputs=gr.outputs.JSON(), # Output as JSON
88
  title="Waste Classifier",
89
  description="Upload an image to classify and get disposal instructions."