vubang commited on
Commit
3b59cab
1 Parent(s): 9a3d9e3

Upload 3 files

Browse files
Files changed (3) hide show
  1. AIRI_logo.png +0 -0
  2. RCAIoT_logo.png +0 -0
  3. app.py +116 -0
AIRI_logo.png ADDED
RCAIoT_logo.png ADDED
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load the saved ResNet model
7
+ model_resnet = []#tf.keras.models.load_model("path_to_your_saved_model/resnet_model.h5")
8
+
9
+ # Set page configuration and layout
10
+ st.set_page_config(
11
+ page_title="Image Classification App",
12
+ page_icon=":camera:",
13
+ layout="wide",
14
+ )
15
+
16
+ # Header logo
17
+ st.image("RCAIoT_logo.png", use_column_width=False)
18
+
19
+ # Main content
20
+ col1, col2 = st.columns([1, 1])
21
+
22
+ with col1:
23
+ st.header("Upload Image")
24
+ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"], key="upload_image")
25
+ if uploaded_image is not None:
26
+ # Display the uploaded image with fixed initial height and width using HTML/CSS
27
+ st.image(uploaded_image, caption="Uploaded Image", use_column_width=False, width=300)
28
+ st.markdown(
29
+ """
30
+ <style>
31
+ img {
32
+ max-height: 300px;
33
+ }
34
+ </style>
35
+ """,
36
+ unsafe_allow_html=True,
37
+ )
38
+
39
+ with col2:
40
+ st.header("Results")
41
+
42
+ # Stylish Analyze and Reset buttons in a horizontal row
43
+ st.markdown(
44
+ """
45
+ <style>
46
+ .analyze-reset-buttons {
47
+ display: flex;
48
+ justify-content: space-between;
49
+ align-items: center;
50
+ }
51
+ .analyze-reset-buttons button {
52
+ flex: 1;
53
+ margin: 10px;
54
+ padding: 10px;
55
+ background-color: #3366ff;
56
+ color: white;
57
+ font-size: 16px;
58
+ text-align: center;
59
+ border: none;
60
+ border-radius: 5px;
61
+ cursor: pointer;
62
+ transition: background-color 0.3s ease;
63
+ }
64
+ .analyze-reset-buttons button:hover {
65
+ background-color: #2353b4;
66
+ }
67
+ .results-text {
68
+ font-size: 24px;
69
+ font-weight: bold;
70
+ margin-top: 20px;
71
+ color: #000;
72
+ }
73
+ .results-values {
74
+ font-size: 18px;
75
+ font-weight: bold;
76
+ margin-top: 10px;
77
+ color: blue;
78
+ }
79
+ </style>
80
+ """,
81
+ unsafe_allow_html=True,
82
+ )
83
+
84
+ st.markdown("<div class='analyze-reset-buttons'>", unsafe_allow_html=True)
85
+ if st.button("Analyze", key="analyze_button"):
86
+ if uploaded_image is not None:
87
+ # Preprocess the uploaded image
88
+ img = Image.open(uploaded_image)
89
+ img = img.resize((64, 64)) # Resize the image to match the model input size
90
+ img = np.array(img)
91
+ img = tf.keras.applications.resnet50.preprocess_input(img)
92
+ img = np.expand_dims(img, axis=0) # Add batch dimension
93
+
94
+ # Make predictions using the loaded model
95
+ predictions = model_resnet.predict(img)
96
+
97
+ # Get the class label with the highest probability
98
+ class_label = np.argmax(predictions)
99
+ confidence = predictions[0][class_label]
100
+
101
+ # Display prediction and confidence
102
+ st.markdown(
103
+ f"<div class='results-text'>Predicted Class: <span class='results-values'>{class_label}</span></div>",
104
+ unsafe_allow_html=True,
105
+ )
106
+ st.markdown(
107
+ f"<div class='results-text'>Confidence Level: <span class='results-values'>{confidence:.2f}</span></div>",
108
+ unsafe_allow_html=True,
109
+ )
110
+ else:
111
+ st.warning("Please upload an image before clicking 'Analyze'.")
112
+ if st.button("Reset", key="reset_button"):
113
+ st.session_state.uploaded_image = None
114
+ uploaded_image = None
115
+ st.empty() # Clear the results container
116
+ st.markdown("</div>", unsafe_allow_html=True)