ibrahimnomad
commited on
Commit
•
4e1c62f
1
Parent(s):
6619b09
Upload 2 files
Browse files- app.py +32 -0
- repuirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from tensorflow.keras.applications.resnet50 import ResNet50
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
st.title("Image Classification with ResNet50 :baby:")
|
8 |
+
|
9 |
+
uploaded_file = st.file_uploader("Upload an image on a object,animal,plant etc.", type=["jpg", "jpeg","png"])
|
10 |
+
|
11 |
+
if uploaded_file is not None:
|
12 |
+
img = image.load_img(uploaded_file, target_size=(224, 224))
|
13 |
+
img = image.img_to_array(img)
|
14 |
+
img = np.expand_dims(img, axis=0)
|
15 |
+
img = preprocess_input(img)
|
16 |
+
|
17 |
+
model = ResNet50(weights='imagenet')
|
18 |
+
pred = model.predict(img)
|
19 |
+
decoded_pred = decode_predictions(pred, top=3)[0]
|
20 |
+
|
21 |
+
st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
|
22 |
+
|
23 |
+
sentence = "This image is "
|
24 |
+
for i, (code, name, probability) in enumerate(decoded_pred):
|
25 |
+
if i == 0:
|
26 |
+
top_name = name.lower()
|
27 |
+
sentence += f"{probability * 100:.2f}% a {top_name}"
|
28 |
+
else:
|
29 |
+
sentence += f", {probability * 100:.2f}% a {name.lower()}"
|
30 |
+
sentence += "."
|
31 |
+
st.markdown(f"<h1>{top_name.upper()}</h1>", unsafe_allow_html=True)
|
32 |
+
st.write(sentence)
|
repuirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
tensorflow
|
3 |
+
numpy
|