vmath commited on
Commit
213d255
·
1 Parent(s): 821b3af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -21
app.py CHANGED
@@ -11,27 +11,15 @@ model_path = "IYRI1.h5"
11
  # Load the model and label encoder
12
  model = load_model(model_path)
13
 
14
- # Define the prediction function
15
- def predict_image(image):
16
- # Preprocess the image
17
- image = Image.fromarray(image.astype('uint8'))
18
- image = image.resize((100, 100))
19
- image = img_to_array(image) / 255.0
20
- image = np.expand_dims(image, axis=0)
21
-
22
- # Make predictions
23
- prediction = model.predict(image)
24
- predicted_class = label_encoder.inverse_transform(np.argmax(prediction))
25
-
26
- return predicted_class[0]
27
-
28
- # Define the input and output interfaces
29
- input_image = gr.inputs.Image(shape=(100, 100))
30
- output_text = gr.outputs.Textbox()
31
-
32
- # Create the Gradio interface
33
- iface = gr.Interface(fn=predict_image, inputs=input_image, outputs=output_text, title="Dog Cat Classifier",
34
- server_name="localhost", server_port=8000, share = True, debug=True)
35
 
 
36
 
 
37
  iface.launch()
 
11
  # Load the model and label encoder
12
  model = load_model(model_path)
13
 
14
+ class_names = ["Cat", "Dog"]
15
+ def predict_input_image(img):
16
+ img_4d=img.reshape(-1,100,100,3)
17
+ prediction=model.predict(img_4d)[0]
18
+ return {class_names[i]: float(prediction[i]) for i in range(2)}
19
+ image = gr.inputs.Image(shape=(100,100))
20
+ label = gr.outputs.Label(num_top_classes=2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ iface = gr.Interface(fn=predict_input_image, inputs=image, outputs=label,title="IYRI Classifier 1",interpretation='default').launch(debug='True')
23
 
24
+ # Run the Gradio interface
25
  iface.launch()