Download app.py from tspsram/loop: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/spaces/tspsram/loop/resolve/main/app.py
- Command line
-
hf download hf://spaces/tspsram/loop/app.py
-
curl -L -o app.py https://huggingface.co/spaces/tspsram/loop/resolve/main/app.py
2.56 kB
| import streamlit as st | |
| import time | |
| # Function to update the progress bar color based on the progress | |
| def update_progress_bar_color(progress): | |
| if progress < 0.3: | |
| return '#800080' # Purple | |
| elif progress < 0.7: | |
| return '#00ffff' # Cyan | |
| else: | |
| return '#00ff00' # Lime Green | |
| # Function to demonstrate a for loop with colorful output | |
| def demonstrate_for_loop(n): | |
| progress_bar = st.progress(0) # Initialize the progress bar | |
| st.markdown('<h3 style="color:#1E90FF;">For Loop Executing...</h3>', unsafe_allow_html=True) | |
| result = "" | |
| for i in range(1, n + 1): | |
| color = "teal" if i % 2 == 0 else "orange" | |
| result += f'<span style="color:{color}; font-size:24px; font-weight:bold;">{i} </span>' | |
| # Update the progress | |
| progress = i / n | |
| progress_bar.progress(progress) | |
| # Display results in real-time | |
| st.markdown(f'<div style="background-color:#fffacd; padding:20px; border-radius:10px; box-shadow: 0px 4px 12px rgba(0,0,0,0.1);">' | |
| f'<strong>For Loop result:</strong> {result}</div>', unsafe_allow_html=True) | |
| time.sleep(0.5) # Simulate execution time | |
| # Function to demonstrate a while loop with colorful output | |
| def demonstrate_while_loop(n): | |
| progress_bar = st.progress(0) # Initialize the progress bar | |
| st.markdown('<h3 style="color:#1E90FF;">While Loop Executing...</h3>', unsafe_allow_html=True) | |
| result = "" | |
| i = 1 | |
| while i <= n: | |
| color = "teal" if i % 2 == 0 else "orange" | |
| result += f'<span style="color:{color}; font-size:24px; font-weight:bold;">{i} </span>' | |
| # Update the progress | |
| progress = i / n | |
| progress_bar.progress(progress) | |
| # Display results in real-time | |
| st.markdown(f'<div style="background-color:#fffacd; padding:20px; border-radius:10px; box-shadow: 0px 4px 12px rgba(0,0,0,0.1);">' | |
| f'<strong>While Loop result:</strong> {result}</div>', unsafe_allow_html=True) | |
| time.sleep(0.5) # Simulate execution time | |
| i += 1 | |
| # Streamlit app layout | |
| st.title("Loop Demonstrator App") | |
| st.markdown("This app demonstrates a for loop and a while loop with colorful outputs.") | |
| # User inputs | |
| n = st.number_input("Enter a number:", min_value=1, value=1) | |
| loop_type = st.selectbox("Select Loop Type:", ["For Loop", "While Loop"]) | |
| # Button to trigger the loop demonstration | |
| if st.button('Run Loop'): | |
| if loop_type == 'For Loop': | |
| demonstrate_for_loop(n) | |
| else: | |
| demonstrate_while_loop(n) | |