Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
# from img_classification import teachable_machine_classification
|
3 |
+
from PIL import Image, ImageOps
|
4 |
+
import streamlit_authenticator as stauth
|
5 |
+
import yaml
|
6 |
+
from yaml.loader import SafeLoader
|
7 |
+
import numpy as np
|
8 |
+
from deepface import DeepFace
|
9 |
+
import cv2
|
10 |
+
|
11 |
+
# authentification
|
12 |
+
with open('./bla.yaml') as file:
|
13 |
+
config = yaml.load(file, Loader=SafeLoader)
|
14 |
+
authenticator = stauth.Authenticate(
|
15 |
+
config['credentials'],
|
16 |
+
config['cookie']['name'],
|
17 |
+
config['cookie']['key'],
|
18 |
+
config['cookie']['expiry_days'],
|
19 |
+
config['preauthorized']
|
20 |
+
)
|
21 |
+
|
22 |
+
name, authentication_status, username = authenticator.login('Login', 'main')
|
23 |
+
if authentication_status:
|
24 |
+
authenticator.logout('Logout', 'main')
|
25 |
+
page = st.sidebar.selectbox("探索或预测", ("苹果病分类","bla"))
|
26 |
+
|
27 |
+
if page == "苹果病分类":
|
28 |
+
st.title("使用谷歌的可教机器进行图像分类")
|
29 |
+
st.header("苹果病")
|
30 |
+
st.text("上传彩色苹果叶子图片")
|
31 |
+
|
32 |
+
uploaded_file = st.file_uploader("选择..", type=["jpg","png","jpeg"])
|
33 |
+
if uploaded_file is not None:
|
34 |
+
image = Image.open(uploaded_file).convert('RGB')
|
35 |
+
st.image(image, caption='上传了图片。', use_column_width=True)
|
36 |
+
st.write("")
|
37 |
+
st.write("分类...")
|
38 |
+
result = DeepFace.analyze(image,actions=("gender","age"))
|
39 |
+
|
40 |
+
print(result)
|
41 |
+
# label = teachable_machine_classification(image, 'keras_model_apple.h5')
|
42 |
+
# if label == 0:
|
43 |
+
# st.write("苹果结痂")
|
44 |
+
# elif label == 1:
|
45 |
+
# st.write("黑腐病")
|
46 |
+
# elif label == 2:
|
47 |
+
# st.write("雪松苹果锈")
|
48 |
+
# else:
|
49 |
+
# st.write("健康苹果")
|
50 |
+
|
51 |
+
# st.text("类:苹果结痂, 黑腐病, 雪松苹果锈, 健康苹果")
|
52 |
+
|
53 |
+
# 0 apple_scrab
|
54 |
+
# 1 black_rot
|
55 |
+
# 2 cedar_apple_rust
|
56 |
+
# 3 apple_healthy
|
57 |
+
|
58 |
+
|
59 |
+
elif authentication_status == False:
|
60 |
+
st.error('Username/password is incorrect')
|
61 |
+
elif authentication_status == None:
|
62 |
+
st.warning('Please enter your username and password')
|
63 |
+
|