yasso12 commited on
Commit
fb17c78
·
verified ·
1 Parent(s): 3702153

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load the model (make sure the file is named my_modal.h5)
7
+ model = tf.keras.models.load_model("my_model.h5")
8
+ class_names = ['Class 1', 'Class 2', 'Class 3'] # Update with your real classes
9
+
10
+ # Define prediction function
11
+ def predict(image):
12
+ image = image.resize((224, 224)) # Resize to model input shape
13
+ img_array = np.array(image) / 255.0
14
+ img_array = img_array.reshape((1, 224, 224, 3))
15
+ prediction = model.predict(img_array)
16
+ predicted_class = class_names[np.argmax(prediction)]
17
+ confidence = float(np.max(prediction))
18
+ return {predicted_class: confidence}
19
+
20
+ # Create Gradio interface
21
+ gr.Interface(
22
+ fn=predict,
23
+ inputs=gr.Image(type="pil"),
24
+ outputs=gr.Label(num_top_classes=3),
25
+ title="My ML Model"
26
+ ).launch()