Spaces:
Running
Running
Upload streamlit_app.py with huggingface_hub
Browse files- streamlit_app.py +144 -0
streamlit_app.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
|
| 5 |
+
# Page Configuration
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="What is Streamlit?",
|
| 8 |
+
page_icon="π",
|
| 9 |
+
layout="wide",
|
| 10 |
+
initial_sidebar_state="expanded"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Custom CSS for better styling
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<style>
|
| 16 |
+
.stApp {
|
| 17 |
+
max-width: 1200px;
|
| 18 |
+
margin: 0 auto;
|
| 19 |
+
}
|
| 20 |
+
.definition-box {
|
| 21 |
+
background-color: #f0f2f6;
|
| 22 |
+
border-left: 5px solid #3898ec;
|
| 23 |
+
padding: 20px;
|
| 24 |
+
border-radius: 5px;
|
| 25 |
+
margin: 20px 0;
|
| 26 |
+
}
|
| 27 |
+
.code-block {
|
| 28 |
+
background-color: #282c34;
|
| 29 |
+
color: #abb2bf;
|
| 30 |
+
padding: 15px;
|
| 31 |
+
border-radius: 5px;
|
| 32 |
+
font-family: 'Courier New', monospace;
|
| 33 |
+
}
|
| 34 |
+
.tooltip {
|
| 35 |
+
position: relative;
|
| 36 |
+
display: inline-block;
|
| 37 |
+
border-bottom: 1px dotted black;
|
| 38 |
+
cursor: help;
|
| 39 |
+
}
|
| 40 |
+
</style>
|
| 41 |
+
""", unsafe_allow_html=True)
|
| 42 |
+
|
| 43 |
+
# Header Section
|
| 44 |
+
st.title("π What is Streamlit?")
|
| 45 |
+
st.markdown("An interactive, web-based framework for building data science applications and machine learning prototypes.")
|
| 46 |
+
|
| 47 |
+
# Footer
|
| 48 |
+
st.markdown("---")
|
| 49 |
+
st.markdown("Built with anycoder | [Link](https://huggingface.co/spaces/akhaliq/anycoder)")
|
| 50 |
+
|
| 51 |
+
# Main Content
|
| 52 |
+
col1, col2 = st.columns([2, 1])
|
| 53 |
+
|
| 54 |
+
with col1:
|
| 55 |
+
st.header("π Definition")
|
| 56 |
+
|
| 57 |
+
definition_box = st.container()
|
| 58 |
+
with definition_box:
|
| 59 |
+
st.markdown("""
|
| 60 |
+
<div class='definition-box'>
|
| 61 |
+
<p><strong>Streamlit</strong> is an open-source Python library that lets you create beautiful, custom web apps for machine learning and data science projects in minutes.</p>
|
| 62 |
+
<br>
|
| 63 |
+
<p>Instead of writing HTML, CSS, and JavaScript, you write simple Python scripts. Streamlit automatically handles the frontend, allowing you to focus on the logic and algorithms.</p>
|
| 64 |
+
</div>
|
| 65 |
+
""", unsafe_allow_html=True)
|
| 66 |
+
|
| 67 |
+
st.subheader("Key Features")
|
| 68 |
+
features = [
|
| 69 |
+
"β
<strong>Rapid Development:</strong> Build apps in minutes, not weeks.",
|
| 70 |
+
"β
<strong>No Frontend Knowledge Required:</strong> Pure Python.",
|
| 71 |
+
"β
<strong>Real-time Interactivity:</strong> Widgets, sliders, and plots update instantly.",
|
| 72 |
+
"β
<strong>Open Source:</strong> Free to use and contribute to.",
|
| 73 |
+
"β
<strong>Community Support:</strong> Large community of users and developers."
|
| 74 |
+
]
|
| 75 |
+
for feature in features:
|
| 76 |
+
st.markdown(feature, unsafe_allow_html=True)
|
| 77 |
+
|
| 78 |
+
with col2:
|
| 79 |
+
st.header("π» How it Works")
|
| 80 |
+
|
| 81 |
+
st.info("""
|
| 82 |
+
1. **Script Execution**: Streamlit reads your Python script from top to bottom.
|
| 83 |
+
2. **Widget Creation**: It automatically converts inputs into interactive UI elements.
|
| 84 |
+
3. **State Management**: It tracks the state of the app and re-runs the script when data changes.
|
| 85 |
+
4. **UI Rendering**: It generates HTML, CSS, and JavaScript for the browser.
|
| 86 |
+
""")
|
| 87 |
+
|
| 88 |
+
st.header("π― Use Cases")
|
| 89 |
+
use_cases = [
|
| 90 |
+
"Data Exploration",
|
| 91 |
+
"Machine Learning Prototypes",
|
| 92 |
+
"Dashboards & Reports",
|
| 93 |
+
"Explainable AI (XAI)",
|
| 94 |
+
"Automated Workflows"
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
for uc in use_cases:
|
| 98 |
+
st.markdown(f"- {uc}")
|
| 99 |
+
|
| 100 |
+
st.markdown("---")
|
| 101 |
+
|
| 102 |
+
# Interactive Demo Section
|
| 103 |
+
st.header("π― Try It Yourself: The Hello World of Streamlit")
|
| 104 |
+
|
| 105 |
+
st.markdown("""
|
| 106 |
+
Below is a simple code snippet that creates an interactive counter.
|
| 107 |
+
In Streamlit, you don't need to write complex HTML formsβjust use the `st.write()` and `st.button()` functions.
|
| 108 |
+
""")
|
| 109 |
+
|
| 110 |
+
code_example = """
|
| 111 |
+
import streamlit as st
|
| 112 |
+
|
| 113 |
+
st.title("Hello Streamlit!")
|
| 114 |
+
|
| 115 |
+
# Create a button
|
| 116 |
+
if st.button("Click Me"):
|
| 117 |
+
st.write("Button clicked! π")
|
| 118 |
+
st.write(f"Count: {st.session_state.get('count', 0) + 1}")
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
st.markdown("### Example Code")
|
| 122 |
+
st.code(code_example, language="python")
|
| 123 |
+
|
| 124 |
+
st.markdown("### Live Demo")
|
| 125 |
+
st.info("Copy the code above into a Python file and run it with `streamlit run filename.py` to see it in action!")
|
| 126 |
+
|
| 127 |
+
# Additional Resources
|
| 128 |
+
st.markdown("---")
|
| 129 |
+
st.header("π Additional Resources")
|
| 130 |
+
|
| 131 |
+
st.markdown("""
|
| 132 |
+
### Official Documentation
|
| 133 |
+
- [Streamlit Docs](https://docs.streamlit.io/) - Comprehensive guides and API reference.
|
| 134 |
+
- [Streamlit Gallery](https://streamlit.io/gallery) - See what others have built.
|
| 135 |
+
|
| 136 |
+
### Getting Started
|
| 137 |
+
- **Installation**: `pip install streamlit`
|
| 138 |
+
- **Running an App**: `streamlit run your_app.py`
|
| 139 |
+
- **Command Line**: `streamlit run your_app.py --server.port 8080`
|
| 140 |
+
""")
|
| 141 |
+
|
| 142 |
+
# Footer
|
| 143 |
+
st.markdown("---")
|
| 144 |
+
st.markdown("Built with anycoder | [Link](https://huggingface.co/spaces/akhaliq/anycoder)")
|