Spaces:
Sleeping
Sleeping
Defkhan5960
commited on
Commit
•
bf24ba2
1
Parent(s):
a52ec0b
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
from PIL import Image
|
4 |
import tensorflow as tf
|
5 |
from tensorflow.keras.preprocessing import image
|
@@ -31,13 +32,29 @@ def classify_image(pil_image):
|
|
31 |
|
32 |
# Get predicted class and confidence
|
33 |
predicted_class = np.argmax(prediction)
|
34 |
-
|
35 |
confidence = prediction[0, np.argmax(prediction)]
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Create the Gradio interface
|
40 |
-
iface = gr.Interface(fn=classify_image, inputs="image", outputs="text")
|
41 |
|
42 |
# Launch the Gradio interface
|
43 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
from PIL import Image
|
5 |
import tensorflow as tf
|
6 |
from tensorflow.keras.preprocessing import image
|
|
|
32 |
|
33 |
# Get predicted class and confidence
|
34 |
predicted_class = np.argmax(prediction)
|
35 |
+
predicted_class_name = waste_labels[predicted_class]
|
36 |
confidence = prediction[0, np.argmax(prediction)]
|
37 |
|
38 |
+
# Get class names and probabilities for all classes
|
39 |
+
class_names = list(waste_labels.values())
|
40 |
+
probabilities = prediction[0]
|
41 |
+
|
42 |
+
# Plot bar chart and save it to a file
|
43 |
+
plt.bar(class_names, probabilities, color='blue')
|
44 |
+
plt.xlabel('Waste Classes')
|
45 |
+
plt.ylabel('Probability')
|
46 |
+
plt.title('Prediction Probabilities')
|
47 |
+
plt.savefig('prediction_plot.png')
|
48 |
+
|
49 |
+
# Prepare output text with all class probabilities
|
50 |
+
output_text = f"Predicted Class: {predicted_class_name}, Confidence: {confidence:.4f}\n"
|
51 |
+
for class_name, prob in zip(class_names, probabilities):
|
52 |
+
output_text += f"{class_name}: {prob:.4f}\n"
|
53 |
+
|
54 |
+
return output_text, 'prediction_plot.png'
|
55 |
|
56 |
# Create the Gradio interface
|
57 |
+
iface = gr.Interface(fn=classify_image, inputs="image", outputs=["text", "image"],live=True)
|
58 |
|
59 |
# Launch the Gradio interface
|
60 |
iface.launch()
|