Spaces:
Sleeping
Sleeping
mandali8686
commited on
Commit
•
35f8363
1
Parent(s):
16d9687
Update app.py
Browse files
app.py
CHANGED
@@ -13,39 +13,32 @@ def load_model():
|
|
13 |
model = load_model()
|
14 |
|
15 |
# Function to apply transforms to the image (update as per your model's requirement)
|
16 |
-
def
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
-
def display_prediction(top_classes, top_probs):
|
25 |
-
for i, (cls, prob) in enumerate(zip(top_classes, top_probs)):
|
26 |
-
st.write(f"{i+1}: {cls} - {prob:.2%}")
|
27 |
|
28 |
-
# Load the class indices (you will need to have a class_indices.json file)
|
29 |
-
class_indices = load_class_indices()
|
30 |
|
31 |
-
# Streamlit interface
|
32 |
-
st.title("Petn Emotion Recognition")
|
33 |
-
st.write("Upload a pet facial image.")
|
34 |
|
35 |
# File uploader
|
36 |
-
uploaded_file = st.file_uploader("", type=["jpg", "png", "jpeg"])
|
37 |
if uploaded_file is not None:
|
38 |
-
# Display the uploaded image
|
39 |
image = Image.open(uploaded_file).convert('RGB')
|
40 |
-
st.image(image, use_column_width=True)
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
13 |
model = load_model()
|
14 |
|
15 |
# Function to apply transforms to the image (update as per your model's requirement)
|
16 |
+
def transform_image(image):
|
17 |
+
transform = transforms.Compose([
|
18 |
+
transforms.Resize((224, 224)), # Resize to the input size that your model expects
|
19 |
+
transforms.ToTensor(),
|
20 |
+
# Add other transformations as needed
|
21 |
+
])
|
22 |
+
return transform(image).unsqueeze(0) # Add batch dimension
|
23 |
|
24 |
+
st.title("Animal Facial Expression Recognition")
|
|
|
|
|
|
|
25 |
|
|
|
|
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
# File uploader
|
29 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
30 |
if uploaded_file is not None:
|
|
|
31 |
image = Image.open(uploaded_file).convert('RGB')
|
32 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
33 |
+
st.write("")
|
34 |
+
st.write("Classifying...")
|
35 |
+
|
36 |
+
# Transform the image
|
37 |
+
input_tensor = transform_image(image)
|
38 |
+
|
39 |
+
# Make prediction
|
40 |
+
with torch.no_grad():
|
41 |
+
prediction = model(input_tensor)
|
42 |
+
|
43 |
+
# Display the prediction (modify as per your output)
|
44 |
+
st.write('Predicted class:', prediction.argmax().item())
|