zlf18 commited on
Commit
631f3cd
Β·
verified Β·
1 Parent(s): 53c18b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -56
app.py CHANGED
@@ -133,78 +133,109 @@ def load_preloaded_model(model_name):
133
  def load_uploaded_model(temp_file):
134
  return gr.update(value=temp_file.name), gr.update(value=DEFAULT_CAMERA)
135
 
 
 
 
 
 
 
 
 
 
136
 
137
- # 9. --- Create and launch the Gradio Interface ---
138
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
139
 
140
- camera_state = gr.State(value=DEFAULT_CAMERA)
141
- prev_hand_pos_state = gr.State(value=None)
142
-
143
- with gr.Row():
144
- gr.Markdown("# πŸ–οΈ Gesture-Controlled 3D Viewer")
145
-
146
- with gr.Row():
147
- # --- UI Column for controls ---
148
  with gr.Column(scale=1):
149
- gr.Markdown("### 1. Select a Model")
150
- with gr.Tabs():
151
- with gr.Tab("Your Presets"):
152
- radio_picker = gr.Radio(
153
- choices=list(PRELOADED_MODELS.keys()),
154
- label="Select your preset model",
155
- value="Preset 1"
156
- )
157
- with gr.Tab("Upload"):
158
- file_uploader = gr.File(
159
- label="Upload .stl, .obj, .glb, or .3mf",
160
- file_types=['.stl', '.obj', '.glb', '.gltf', '.3mf']
161
- )
162
-
163
- gr.Markdown("### 2. Control with Webcam")
164
- webcam_input = gr.Image(sources=["webcam"], streaming=True, label="Webcam Feed")
165
-
166
- gr.Markdown("### 3. Gesture Status")
167
- text_output = gr.Text(label="Status")
168
-
169
- # --- MAIN COLUMN for 3D viewer ---
170
- with gr.Column(scale=3):
171
- default_model_path = PRELOADED_MODELS.get("Preset 1", None)
172
- if not os.path.exists(default_model_path):
173
- print(f"Warning: Default preset '{default_model_path}' not found.")
174
- default_model_path = None
175
-
176
- model_3d = gr.Model3D(
177
- value=default_model_path,
178
- label=None,
179
- camera_position=DEFAULT_CAMERA,
180
- interactive=False
181
- )
182
-
183
- gr.Markdown(
184
- """
185
- <div style="width: 100%; text-align: center;">
186
- <b>Gesture Controls:</b> ✌️ <b>Peace Sign:</b> Reset/Home | πŸ‘Œ <b>Pinch & Move:</b> Rotate | ✊ <b>Fist & Move Left/Right:</b> Zoom
187
- </div>
188
- """
189
- )
190
 
191
- # --- 10. WIRE UP THE NEW CONTROLS ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
- # 1. Wire up the Radio buttons
194
  radio_picker.change(
195
  fn=load_preloaded_model,
196
  inputs=radio_picker,
197
  outputs=[model_3d, camera_state]
198
  )
199
 
200
- # 2. Wire up the File uploader
201
  file_uploader.upload(
202
  fn=load_uploaded_model,
203
  inputs=file_uploader,
204
  outputs=[model_3d, camera_state]
205
  )
206
 
207
- # 3. Wire up the webcam gesture controls
208
  webcam_input.stream(
209
  fn=process_image,
210
  inputs=[
@@ -223,5 +254,6 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
223
  # ---
224
  # THIS IS THE LAUNCH COMMAND FOR HUGGING FACE
225
  # ---
226
- # (Remember to change your password!)
227
- demo.launch(share=True, auth=("guest", "itszion18"))
 
 
133
  def load_uploaded_model(temp_file):
134
  return gr.update(value=temp_file.name), gr.update(value=DEFAULT_CAMERA)
135
 
136
+ # --- 9. NEW: LOGIN FUNCTION ---
137
+ def login_function(password):
138
+ # --- SET YOUR PASSWORD HERE ---
139
+ if password == "Its_zion_18":
140
+ # Return updates to hide login and show app
141
+ return gr.update(visible=False), gr.update(visible=True), gr.update(value="")
142
+ else:
143
+ # Return updates to show error
144
+ return gr.update(visible=True), gr.update(visible=False), gr.update(value="Incorrect Password")
145
 
146
+ # --- 10. Create and launch the Gradio Interface ---
147
  with gr.Blocks(theme=gr.themes.Glass()) as demo:
148
 
149
+ # --- This row is the LOGIN SCREEN (visible by default) ---
150
+ with gr.Row(visible=True) as login_page:
 
 
 
 
 
 
151
  with gr.Column(scale=1):
152
+ pass # Empty spacer
153
+ with gr.Column(scale=2):
154
+ gr.Markdown("# πŸ–οΈ Gesture-Controlled 3D Viewer")
155
+ gr.Markdown("Please enter the password to continue.")
156
+ password_input = gr.Textbox(label="Password", type="password")
157
+ login_button = gr.Button("Login")
158
+ error_output = gr.Textbox(label="Error", interactive=False)
159
+ with gr.Column(scale=1):
160
+ pass # Empty spacer
161
+
162
+ # --- This column is the MAIN APP (hidden by default) ---
163
+ with gr.Column(visible=False) as main_app:
164
+ camera_state = gr.State(value=DEFAULT_CAMERA)
165
+ prev_hand_pos_state = gr.State(value=None)
166
+
167
+ with gr.Row():
168
+ gr.Markdown("# πŸ–οΈ Gesture-Controlled 3D Viewer")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
+ with gr.Row():
171
+ # --- UI Column for controls ---
172
+ with gr.Column(scale=1):
173
+ gr.Markdown("### 1. Select a Model")
174
+ with gr.Tabs():
175
+ with gr.Tab("Your Presets"):
176
+ radio_picker = gr.Radio(
177
+ choices=list(PRELOADED_MODELS.keys()),
178
+ label="Select your preset model",
179
+ value="Preset 1"
180
+ )
181
+ with gr.Tab("Upload"):
182
+ file_uploader = gr.File(
183
+ label="Upload .stl, .obj, .glb, or .3mf",
184
+ file_types=['.stl', '.obj', '.glb', '.gltf', '.3mf']
185
+ )
186
+
187
+ gr.Markdown("### 2. Control with Webcam")
188
+ webcam_input = gr.Image(sources=["webcam"], streaming=True, label="Webcam Feed")
189
+
190
+ gr.Markdown("### 3. Gesture Status")
191
+ text_output = gr.Text(label="Status")
192
+
193
+ # --- MAIN COLUMN for 3D viewer ---
194
+ with gr.Column(scale=3):
195
+ default_model_path = PRELOADED_MODELS.get("Preset 1", None)
196
+ if not os.path.exists(default_model_path):
197
+ print(f"Warning: Default preset '{default_model_path}' not found.")
198
+ default_model_path = None
199
+
200
+ model_3d = gr.Model3D(
201
+ value=default_model_path,
202
+ label=None,
203
+ camera_position=DEFAULT_CAMERA,
204
+ interactive=False
205
+ )
206
+
207
+ gr.Markdown(
208
+ """
209
+ <div style="width: 100%; text-align: center;">
210
+ <b>Gesture Controls:</b> ✌️ <b>Peace Sign:</b> Reset/Home | πŸ‘Œ <b>Pinch & Move:</b> Rotate | ✊ <b>Fist & Move Left/Right:</b> Zoom
211
+ </div>
212
+ """
213
+ )
214
+
215
+ # --- 11. WIRE UP ALL CONTROLS ---
216
+
217
+ # 1. Wire up the Login Button
218
+ login_button.click(
219
+ fn=login_function,
220
+ inputs=password_input,
221
+ outputs=[login_page, main_app, error_output]
222
+ )
223
 
224
+ # 2. Wire up the Radio buttons
225
  radio_picker.change(
226
  fn=load_preloaded_model,
227
  inputs=radio_picker,
228
  outputs=[model_3d, camera_state]
229
  )
230
 
231
+ # 3. Wire up the File uploader
232
  file_uploader.upload(
233
  fn=load_uploaded_model,
234
  inputs=file_uploader,
235
  outputs=[model_3d, camera_state]
236
  )
237
 
238
+ # 4. Wire up the webcam gesture controls
239
  webcam_input.stream(
240
  fn=process_image,
241
  inputs=[
 
254
  # ---
255
  # THIS IS THE LAUNCH COMMAND FOR HUGGING FACE
256
  # ---
257
+ # We add share=True to fix the ValueError, but remove auth=
258
+ # because the app now handles its own login.
259
+ demo.launch(share=True)