Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
import tensorflow as tf
|
3 |
-
from tensorflow.keras.preprocessing import image
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
import numpy as np
|
6 |
-
from PIL import Image as PIL_Image
|
7 |
-
# Load the model
|
8 |
-
model = tf.keras.models.load_model('dogcat_model_bak.h5')
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
# Preprocess the image
|
13 |
-
img1 = pil_img.resize((64, 64))
|
14 |
-
img2 = pil_img
|
15 |
-
img = image.img_to_array(img1)
|
16 |
-
img = img / 255.0
|
17 |
-
img = np.expand_dims(img, axis=0)
|
18 |
-
# Make prediction
|
19 |
-
prediction = model.predict(img)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
value = 'Dog: %1.2f' % prediction[0][0]
|
24 |
-
plt.text(20, 62, value, color='red', fontsize=18, bbox=dict(facecolor='white', alpha=0.8))
|
25 |
-
else:
|
26 |
-
value = 'Cat: %1.2f' % (1.0 - prediction[0][0])
|
27 |
-
plt.text(20, 62, value, color='red', fontsize=18, bbox=dict(facecolor='white', alpha=0.8))
|
28 |
-
|
29 |
-
plt.imshow(img2)
|
30 |
-
plt.axis('off') # Hide axis for better visualization
|
31 |
-
plt.show()
|
32 |
-
|
33 |
-
return img2 # Return the image with prediction annotations
|
34 |
-
|
35 |
-
# Interface creation using Gradio
|
36 |
-
inputs = gr.Image()
|
37 |
-
interface = gr.Interface(fn = classify_image, inputs=gr.Image(),outputs=classify_image(inputs))
|
38 |
-
# Load and pre, capture_session=True)
|
39 |
-
|
40 |
-
# Launch the Gradio app
|
41 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
def image_classifier(inp):
|
4 |
+
return {'cat': 0.3, 'dog': 0.7}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
|
7 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|