Spaces:
Sleeping
Sleeping
Milind Kamat
commited on
Commit
·
0ad02c4
1
Parent(s):
ca54b24
2024 dec 30 method update
Browse filesSigned-off-by: Milind Kamat <36366961+milindkamat0507@users.noreply.github.com>
app.py
CHANGED
|
@@ -347,59 +347,62 @@ class StreamlitTutorial:
|
|
| 347 |
|
| 348 |
|
| 349 |
def get_input_elements(self) -> List[Tuple[str, str]]:
|
| 350 |
-
"""
|
|
|
|
|
|
|
| 351 |
return [
|
| 352 |
("Text Input", """st.text_input('Enter your name',
|
| 353 |
-
key='
|
| 354 |
placeholder='John Doe')"""),
|
| 355 |
|
| 356 |
("Text Area", """st.text_area('Enter long text',
|
| 357 |
-
key='
|
| 358 |
height=100,
|
| 359 |
placeholder='Write something...')"""),
|
| 360 |
|
| 361 |
("Number Input", """st.number_input('Enter a number',
|
| 362 |
-
key='
|
| 363 |
min_value=0,
|
| 364 |
max_value=100,
|
| 365 |
value=50,
|
| 366 |
step=5)"""),
|
| 367 |
|
| 368 |
("Slider", """st.slider('Select value',
|
| 369 |
-
key='
|
| 370 |
min_value=0,
|
| 371 |
max_value=100,
|
| 372 |
value=50,
|
| 373 |
step=5)"""),
|
| 374 |
|
| 375 |
("Select Box", """st.selectbox('Choose an option',
|
| 376 |
-
key='
|
| 377 |
options=['Option 1', 'Option 2', 'Option 3'],
|
| 378 |
index=0)""")
|
| 379 |
]
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
|
|
|
|
|
|
| 390 |
|
| 391 |
-
with st.container(border=True, key=
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
|
| 404 |
|
| 405 |
|
|
|
|
| 347 |
|
| 348 |
|
| 349 |
def get_input_elements(self) -> List[Tuple[str, str]]:
|
| 350 |
+
"""
|
| 351 |
+
Cross-validated collection of input widgets with unique keys
|
| 352 |
+
"""
|
| 353 |
return [
|
| 354 |
("Text Input", """st.text_input('Enter your name',
|
| 355 |
+
key='text_input_demo_1',
|
| 356 |
placeholder='John Doe')"""),
|
| 357 |
|
| 358 |
("Text Area", """st.text_area('Enter long text',
|
| 359 |
+
key='text_area_demo_1',
|
| 360 |
height=100,
|
| 361 |
placeholder='Write something...')"""),
|
| 362 |
|
| 363 |
("Number Input", """st.number_input('Enter a number',
|
| 364 |
+
key='number_input_demo_1',
|
| 365 |
min_value=0,
|
| 366 |
max_value=100,
|
| 367 |
value=50,
|
| 368 |
step=5)"""),
|
| 369 |
|
| 370 |
("Slider", """st.slider('Select value',
|
| 371 |
+
key='slider_demo_1',
|
| 372 |
min_value=0,
|
| 373 |
max_value=100,
|
| 374 |
value=50,
|
| 375 |
step=5)"""),
|
| 376 |
|
| 377 |
("Select Box", """st.selectbox('Choose an option',
|
| 378 |
+
key='select_box_demo_1',
|
| 379 |
options=['Option 1', 'Option 2', 'Option 3'],
|
| 380 |
index=0)""")
|
| 381 |
]
|
| 382 |
+
|
| 383 |
+
def render_input_elements(self, col: st.delta_generator.DeltaGenerator) -> None:
|
| 384 |
+
"""
|
| 385 |
+
Renders input examples with unique keys for both examples and live output
|
| 386 |
+
"""
|
| 387 |
+
with col:
|
| 388 |
+
st.markdown("### 📝 Code Examples")
|
| 389 |
+
for idx, (title, code) in enumerate(self.get_input_elements()):
|
| 390 |
+
with st.container(border=True, key=f"demo_container_{idx}"):
|
| 391 |
+
st.markdown(f"**{title}**")
|
| 392 |
+
st.code(code)
|
| 393 |
+
st.markdown("Live output:")
|
| 394 |
|
| 395 |
+
with st.container(border=True, key=f"output_container_{idx}"):
|
| 396 |
+
try:
|
| 397 |
+
# Create runtime version with unique key
|
| 398 |
+
runtime_code = code.replace('demo_1', f'runtime_{idx}')
|
| 399 |
+
exec(runtime_code)
|
| 400 |
+
except Exception as e:
|
| 401 |
+
st.error(f"Error: {str(e)}")
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
|
|
|
|
| 406 |
|
| 407 |
|
| 408 |
|