DataRaptor commited on
Commit
0e7de7e
1 Parent(s): 13b518f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
+ import requests
5
+
6
+
7
+ # fix sidebar
8
+ st.markdown("""
9
+ <style>
10
+ .css-vk3wp9 {
11
+ background-color: rgb(255 255 255);
12
+ }
13
+ .css-18l0hbk {
14
+ padding: 0.34rem 1.2rem !important;
15
+ margin: 0.125rem 2rem;
16
+ }
17
+ .css-nziaof {
18
+ padding: 0.34rem 1.2rem !important;
19
+ margin: 0.125rem 2rem;
20
+ background-color: rgb(181 197 227 / 18%) !important;
21
+ }
22
+ </style>
23
+ """, unsafe_allow_html=True
24
+ )
25
+ hide_st_style = """
26
+ <style>
27
+ #MainMenu {visibility: hidden;}
28
+ footer {visibility: hidden;}
29
+ header {visibility: hidden;}
30
+ </style>
31
+ """
32
+ st.markdown(hide_st_style, unsafe_allow_html=True)
33
+
34
+
35
+
36
+
37
+ # Function to load and predict image
38
+ def predict(image):
39
+ # Dummy prediction
40
+ classes = ['cat', 'dog']
41
+ prediction = np.random.rand(len(classes))
42
+ prediction /= np.sum(prediction)
43
+ return dict(zip(classes, prediction))
44
+
45
+ # Define app layout
46
+ #st.set_page_config(page_title='Image Classification App', page_icon=':camera:', layout='wide')
47
+ st.title('HappyWhale')
48
+ st.markdown("[![View in W&B](https://img.shields.io/badge/View%20in-W%26B-blue)](https://wandb.ai/<username>/<project_name>?workspace=user-<username>)")
49
+
50
+ st.markdown('This project aims to identify whales and dolphins by their unique characteristics. It can help researchers understand their behavior, population dynamics, and migration patterns. This project can aid researchers in identifying these marine mammals, providing valuable data for conservation efforts. [[Source Code]](https://kaggle.com/)')
51
+
52
+
53
+ # Add file uploader
54
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
55
+
56
+ # Add test image selector
57
+ test_images = {
58
+ 'Cat': 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg',
59
+ 'Dog': 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Golde33443.jpg/1200px-Golde33443.jpg',
60
+ 'Bird': 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Scarlet_Tanager_-_male_%28cropped%29.jpg/1200px-Scarlet_Tanager_-_male_%28cropped%29.jpg'
61
+ }
62
+ test_image = st.selectbox('Or choose a test image', list(test_images.keys()))
63
+
64
+ st.subheader('Selected Image')
65
+ # Define layout of app
66
+ left_column, right_column = st.columns([1, 2.5], gap="medium")
67
+ with left_column:
68
+
69
+ if uploaded_file is not None:
70
+ image = Image.open(uploaded_file)
71
+ st.image(image, use_column_width=True)
72
+ else:
73
+ image_url = test_images[test_image]
74
+ image = Image.open(requests.get(image_url, stream=True).raw)
75
+ st.image(image, use_column_width=True)
76
+
77
+
78
+ if st.button('✨ Get prediction from AI', type='primary'):
79
+ spacer = st.empty()
80
+
81
+
82
+ prediction = predict(image)
83
+ right_column.subheader('Results')
84
+ for class_name, class_probability in prediction.items():
85
+ right_column.write(f'{class_name}: {class_probability:.2%}')
86
+ right_column.progress(class_probability)
87
+
88
+
89
+ # Display a footer with links and credits
90
+ st.markdown("---")
91
+ st.markdown("Built by [Shamim Ahamed](https://your-portfolio-website.com/). Data provided by [Kaggle](https://www.kaggle.com/c/)")
92
+ #st.markdown("Data provided by [The Feedback Prize - ELLIPSE Corpus Scoring Challenge on Kaggle](https://www.kaggle.com/c/feedbackprize-ellipse-corpus-scoring-challenge)")
93
+
94
+