Spaces:
Sleeping
Sleeping
Milind Kamat
commited on
Commit
·
df73164
1
Parent(s):
abbb230
xxxx
Browse filesSigned-off-by: Milind Kamat <36366961+milindkamat0507@users.noreply.github.com>
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from typing import List, Dict, Tuple, Optional, Any
|
| 3 |
-
|
| 4 |
class StreamlitTutorial:
|
| 5 |
"""
|
| 6 |
Main class for the Streamlit Tutorial application.
|
|
@@ -380,25 +380,26 @@ class StreamlitTutorial:
|
|
| 380 |
index=0)""")
|
| 381 |
]
|
| 382 |
|
| 383 |
-
def render_input_elements(self, col: st.delta_generator.DeltaGenerator) -> None:
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
|
|
|
| 402 |
|
| 403 |
|
| 404 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from typing import List, Dict, Tuple, Optional, Any
|
| 3 |
+
import traceback
|
| 4 |
class StreamlitTutorial:
|
| 5 |
"""
|
| 6 |
Main class for the Streamlit Tutorial application.
|
|
|
|
| 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 |
|