MrLi008 commited on
Commit
44499df
·
1 Parent(s): 216a91f
Files changed (1) hide show
  1. app.py +52 -44
app.py CHANGED
@@ -23,11 +23,12 @@ def login_user(username, password):
23
  return True
24
  print('login faild')
25
  print(users_db)
 
26
  return False
27
 
28
  def logout_user():
29
  """Log out the current user."""
30
- st.session_state['logged_in'] = False
31
  st.session_state.pop('user', None)
32
  st.session_state.pop('step1_done', None)
33
  st.session_state.pop('step2_done', None)
@@ -59,45 +60,51 @@ def show_login():
59
  st.error("Invalid username or password.")
60
 
61
  def show_task():
62
- """Display the multi-step task."""
63
- st.title(f"Welcome, {st.session_state['user']['name']}!")
64
-
65
- # Step 1: Confirm personal details
66
- st.header("Step 1: Confirm Your Details")
67
- name = st.text_input("Name", value=st.session_state['user']['name'])
68
- age = st.number_input("Age", value=st.session_state['user']['age'], min_value=0, max_value=120, step=1)
69
- if st.button("Submit Step 1"):
70
- st.session_state['user']['name'] = name
71
- st.session_state['user']['age'] = age
72
- st.session_state['step1_done'] = True
73
- st.write(f"Hello, {name}. You are {age} years old.")
74
- time.sleep(1) # Simulate a processing delay
75
-
76
- # Step 2: Update favorite color
77
- if 'step1_done' in st.session_state:
78
- st.header("Step 2: Update Your Favorite Color")
79
- favorite_color = st.text_input("What's your favorite color?", value=st.session_state['user']['favorite_color'])
80
- if st.button("Submit Step 2"):
81
- st.session_state['user']['favorite_color'] = favorite_color
82
- st.session_state['step2_done'] = True
83
- st.write(f"Got it! Your favorite color is {favorite_color}.")
84
- time.sleep(1) # Simulate a processing delay
85
-
86
- # Step 3: Final Confirmation and Real-time Processing
87
- if 'step2_done' in st.session_state:
88
- st.header("Step 3: Final Confirmation")
89
- confirm = st.checkbox("Confirm and process the data")
90
- if confirm:
91
- st.write("Processing data...")
92
- progress_bar = st.progress(0)
93
-
94
- # Simulate a real-time processing task
95
- for i in range(100):
96
- progress_bar.progress(i + 1)
97
- time.sleep(0.05) # Simulate real-time data streaming
98
-
99
- st.success("Task Completed!")
100
- st.write(f"Summary: {name}, {age} years old, likes {favorite_color}.")
 
 
 
 
 
 
101
 
102
  # Option to logout
103
  if st.button("Logout"):
@@ -108,12 +115,13 @@ def main():
108
  st.title("Streamlit Application with Login and Multi-step Task")
109
 
110
  if 'logged_in' not in st.session_state:
111
- st.session_state['logged_in'] = False
112
 
113
- if not st.session_state['logged_in']:
114
- show_registration()
115
  show_login()
116
- else:
 
 
117
  show_task()
118
 
119
  if __name__ == "__main__":
 
23
  return True
24
  print('login faild')
25
  print(users_db)
26
+ st.session_state['logged_in'] = 'login'
27
  return False
28
 
29
  def logout_user():
30
  """Log out the current user."""
31
+ st.session_state['logged_in'] = 'login'
32
  st.session_state.pop('user', None)
33
  st.session_state.pop('step1_done', None)
34
  st.session_state.pop('step2_done', None)
 
60
  st.error("Invalid username or password.")
61
 
62
  def show_task():
63
+
64
+ st.title("Task")
65
+
66
+ # init session_state
67
+ if 'step1' not in st.session_state:
68
+ st.session_state['step1'] = None
69
+ if 'step2' not in st.session_state:
70
+ st.session_state['step2'] = None
71
+ if 'step3' not in st.session_state:
72
+ st.session_state['step3'] = None
73
+ if 'step4' not in st.session_state:
74
+ st.session_state['step4'] = None
75
+
76
+ st.header('step 1: 文案准备')
77
+ st.text_input("请输入文案关键词", key="step1_text")
78
+ st.checkbox("风格", key="step1_voice")
79
+ if st.button("开始生成文案"):
80
+ st.session_state['step1'] = 'done'
81
+
82
+ if st.session_state['step1'] == 'done':
83
+ st.header('step 2: 语音风格')
84
+ st.text_input("语音风格关键词", key="step2_text")
85
+ if st.button("开始生成语音"):
86
+ st.session_state['step2'] = 'done'
87
+
88
+ if st.session_state['step2'] == 'done':
89
+ st.header('step 3: 素材风格')
90
+ st.text_input("请输入素材风格关键词", key="step3_text")
91
+ if st.button("开始载入素材"):
92
+ st.session_state['step3'] = 'done'
93
+
94
+ if st.session_state['step3'] == 'done':
95
+ st.header('step 4: 视频风格')
96
+ st.text_input("请输入视频风格关键词", key="step4_text")
97
+ if st.button("开始合并视频"):
98
+ st.session_state['step4'] = 'done'
99
+
100
+ if st.session_state['step4'] == 'done':
101
+ progress_bar = st.progress(0)
102
+
103
+ # Simulate a real-time processing task
104
+ for i in range(100):
105
+ progress_bar.progress(i + 1)
106
+ time.sleep(0.05) # Simulate real-time data streaming
107
+
108
 
109
  # Option to logout
110
  if st.button("Logout"):
 
115
  st.title("Streamlit Application with Login and Multi-step Task")
116
 
117
  if 'logged_in' not in st.session_state:
118
+ st.session_state['logged_in'] = 'login'
119
 
120
+ if st.session_state['logged_in'] == 'login':
 
121
  show_login()
122
+ elif st.session_state['logged_in'] == 'register':
123
+ show_registration()
124
+ elif st.session_state['logged_in'] == True:
125
  show_task()
126
 
127
  if __name__ == "__main__":