Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
from fastai.vision.all import *
|
2 |
-
from io import BytesIO
|
3 |
-
import requests
|
4 |
-
import streamlit as st
|
5 |
-
|
6 |
-
"""
|
7 |
-
# Sustainable energy classifacation
|
8 |
-
This is a classifier for images ofSustainable energy.
|
9 |
-
"""
|
10 |
-
def predict(img):
|
11 |
-
st.image(img, caption="Your image", use_column_width=True)
|
12 |
-
pred, key, probs = learn_inf.predict(img)
|
13 |
-
# st.write(learn_inf.predict(img))
|
14 |
-
|
15 |
-
f"""
|
16 |
-
### Rediction result: {pred}
|
17 |
-
### Probability of {pred}: {probs[key].item()*100: .2f}%
|
18 |
-
"""
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
path = "./"
|
23 |
-
learn_inf = load_learner(path + "resnet34_stage-1.pkl")
|
24 |
-
|
25 |
-
option = st.radio("", ["Upload Image", "Image URL"])
|
26 |
-
|
27 |
-
if option == "Upload Image":
|
28 |
-
uploaded_file = st.file_uploader("Please upload an image.")
|
29 |
-
|
30 |
-
if uploaded_file is not None:
|
31 |
-
img = PILImage.create(uploaded_file)
|
32 |
-
predict(img)
|
33 |
-
|
34 |
-
else:
|
35 |
-
url = st.text_input("Please input a url.")
|
36 |
-
|
37 |
-
if url != "":
|
38 |
-
try:
|
39 |
-
response = requests.get(url)
|
40 |
-
pil_img = PILImage.create(BytesIO(response.content))
|
41 |
-
predict(pil_img)
|
42 |
-
|
43 |
-
except:
|
44 |
-
st.text("Problem reading image from", url)
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|