kikuepi commited on
Commit
179fa32
ยท
verified ยท
1 Parent(s): 0352c54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -24
app.py CHANGED
@@ -29,8 +29,6 @@ model.eval()
29
  view_flag = True
30
  skip = False
31
 
32
- left_column, right_column = st.columns(2)
33
-
34
  def predict_image(img):
35
  img = img.convert('RGB')
36
  img_transformed = transform(img)
@@ -41,10 +39,9 @@ def predict_image(img):
41
  return preds.item()
42
  uploaded_file = st.file_uploader('Choose an image...', type=['jpg', 'png'])
43
  if uploaded_file:
44
- with left_column:
45
- img = Image.open(uploaded_file)
46
- st.image(img, caption="Uploaded Image", use_column_width=True)
47
- pred = predict_image(img)
48
  if pred == 0:
49
  season_type = "็ง‹"
50
  elif pred == 1:
@@ -57,35 +54,43 @@ if uploaded_file:
57
  st.session_state.show_video = False
58
  if 'skip' not in st.session_state:
59
  st.session_state.skip = False
 
 
60
 
61
  person_result = st.selectbox(
62
  '็ตๆžœใฎไฟฎๆญฃ',
63
  ('ๆ˜ฅ', 'ๅค', '็ง‹', 'ๅ†ฌ')
64
- )
65
 
66
  if person_result:
67
  season_type = person_result
68
 
69
- with left_column:
70
- st.write(f"ใƒ‘ใƒผใ‚ฝใƒŠใƒซใ‚ซใƒฉใƒผใฏ {season_type} ใงใ™")
 
 
 
 
 
71
 
72
- # ใŠใ™ใ™ใ‚ใฎๅ•†ๅ“ใ‚’่ฆ‹ใ‚‹ใƒœใ‚ฟใƒณ
73
  view_recommend = st.button("ใŠใ™ใ™ใ‚ใฎๅ•†ๅ“ใ‚’่ฆ‹ใ‚‹")
74
- with right_column:
75
  if view_recommend:
76
  st.session_state.show_video = True
77
 
78
- # ใ‚นใ‚ญใƒƒใƒ—ใ•ใ‚Œใšใซๅ‹•็”ปใ‚’่กจ็คบใ™ใ‚‹
79
- if st.session_state.show_video and not st.session_state.skip:
80
- st.video("sample.mp4", start_time=0)
81
 
82
- # ๅ‹•็”ปใฎใ‚นใ‚ญใƒƒใƒ—ใƒœใ‚ฟใƒณใŒๆŠผใ•ใ‚ŒใŸใ‚‰ใ€ใƒฌใ‚ณใƒกใƒณใƒ‰ๆ–‡ใ‚’่กจ็คบใ™ใ‚‹
83
- if st.session_state.show_video and not st.session_state.skip:
84
- time.sleep(5)
85
- st.session_state.show_video = False
86
- st.session_state.skip = True
87
- if st.session_state.skip:
88
- st.write(
89
- """
90
- ใƒฌใ‚ณใƒกใƒณใƒ‰ๆ–‡ใงใ™ใ€‚
91
- """)
 
 
 
29
  view_flag = True
30
  skip = False
31
 
 
 
32
  def predict_image(img):
33
  img = img.convert('RGB')
34
  img_transformed = transform(img)
 
39
  return preds.item()
40
  uploaded_file = st.file_uploader('Choose an image...', type=['jpg', 'png'])
41
  if uploaded_file:
42
+ img = Image.open(uploaded_file)
43
+ st.image(img, caption="Uploaded Image", use_column_width=True)
44
+ pred = predict_image(img)
 
45
  if pred == 0:
46
  season_type = "็ง‹"
47
  elif pred == 1:
 
54
  st.session_state.show_video = False
55
  if 'skip' not in st.session_state:
56
  st.session_state.skip = False
57
+ if 'result' not in st.session_state:
58
+ st.session_state.result = False
59
 
60
  person_result = st.selectbox(
61
  '็ตๆžœใฎไฟฎๆญฃ',
62
  ('ๆ˜ฅ', 'ๅค', '็ง‹', 'ๅ†ฌ')
63
+ )
64
 
65
  if person_result:
66
  season_type = person_result
67
 
68
+ st.write(f"ใƒ‘ใƒผใ‚ฝใƒŠใƒซใ‚ซใƒฉใƒผใฏ {season_type} ใงใ™")
69
+
70
+ # ใŠใ™ใ™ใ‚ใฎๅ•†ๅ“ใ‚’่ฆ‹ใ‚‹ใƒœใ‚ฟใƒณ
71
+ view_result = st.button("่จบๆ–ญ็ตๆžœ่ฉณ็ดฐ & ใŠใ™ใ™ใ‚ๅ•†ๅ“ใ‚’่ฆ‹ใ‚‹")
72
+ if view_result or st.session_state.result:
73
+ st.session_state.result = True
74
+ st.image(f"{season_type}.png")
75
 
76
+ if st.session_state.result and not st.session_state.show_video:
77
  view_recommend = st.button("ใŠใ™ใ™ใ‚ใฎๅ•†ๅ“ใ‚’่ฆ‹ใ‚‹")
 
78
  if view_recommend:
79
  st.session_state.show_video = True
80
 
81
+ # ใ‚นใ‚ญใƒƒใƒ—ใ•ใ‚Œใšใซๅ‹•็”ปใ‚’่กจ็คบใ™ใ‚‹
82
+ if st.session_state.show_video and not st.session_state.skip:
83
+ st.video("sample.mp4", start_time=0)
84
 
85
+ # ๅ‹•็”ปใฎใ‚นใ‚ญใƒƒใƒ—ใƒœใ‚ฟใƒณใŒๆŠผใ•ใ‚ŒใŸใ‚‰ใ€ใƒฌใ‚ณใƒกใƒณใƒ‰ๆ–‡ใ‚’่กจ็คบใ™ใ‚‹
86
+ if st.session_state.show_video and not st.session_state.skip:
87
+ time.sleep(5)
88
+ st.session_state.show_video = False
89
+ st.session_state.skip = True
90
+ if st.session_state.skip:
91
+ st.write(
92
+ """
93
+ ใŠใ™ใ™ใ‚ใฎๅ•†ๅ“ใงใ™ใ€‚
94
+ """)
95
+ st.image("ๆœ.png")
96
+