annanau commited on
Commit
0b38715
·
verified ·
1 Parent(s): 8c655b9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ import numpy as np
5
+
6
+ # Load your trained Xception model
7
+ model = tf.keras.models.load_model("your-huggingface-username/your-model-name")
8
+
9
+ def classify_image(img):
10
+ # Preprocess the image
11
+ img = img.resize((299, 299)) # Resize to the input shape of Xception
12
+ img_array = image.img_to_array(img) # Convert image to array
13
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
14
+ img_array /= 255.0 # Normalize the image
15
+
16
+ # Make prediction
17
+ predictions = model.predict(img_array)
18
+ predicted_class = np.argmax(predictions, axis=-1)[0] # Get the predicted class index
19
+
20
+ return str(predicted_class) # Return the class index as a string
21
+
22
+ # Set up Gradio interface
23
+ iface = gr.Interface(fn=classify_image, inputs=gr.inputs.Image(type="pil"), outputs="text")
24
+
25
+ iface.launch()