CoolFace
Apppublic

andrejet/bayesian-simulator

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
readme.md132 linesDownload Raw Back to root
1# 🧾 app.py — Your Streamlit App2 3Streamlit is an open-source app framework used for building and sharing data applications quickly and easily, primarily in Python. It allows developers to create web applications that are interactive and capable of displaying data visualizations, handling user inputs, and showcasing machine learning models with minimal effort, making it particularly popular among data scientists and machine learning engineers.4 5### Key Features of Streamlit:6 71. **Easy to Use**: Streamlit’s API is simple and intuitive, requiring only basic Python knowledge to get started.8 92. **Real-time Interactivity**: Users can interact with the app through widgets such as sliders, buttons, and select boxes, and see the results update in real time.10 113. **Integrated with Data Science Libraries**: Streamlit works well with popular libraries like Pandas, NumPy, Matplotlib, Plotly, and more, allowing you to leverage existing knowledge and tools.12 134. **Deployment Options**: Streamlit apps can be deployed locally or on the cloud through Streamlit Sharing, or other cloud platforms like Heroku or AWS.14 155. **Focus on Data Visualization**: Streamlit makes it easy to create beautiful data visualizations and dashboards to represent data insights effectively.16 17### Basic Example of a Streamlit App:18 19Here’s a simple example of how to create a Streamlit app:20 21```python22import streamlit as st23import pandas as pd24import numpy as np25 26st.title("My First Streamlit App")27 28# Create a simple slider29number = st.slider("Pick a number", 0, 100)30 31# Display a message based on the slider value32st.write(f"You picked: {number}")33 34# Create a dataframe and display it35data = pd.DataFrame({36    'Column 1': np.random.rand(10),37    'Column 2': np.random.rand(10)38})39 40st.write(data)41 42# Create a line chart43st.line_chart(data)44```45 46### Running a Streamlit App:47 48To run a Streamlit app, save your code in a Python file (e.g., `app.py`) and run the following command in your terminal:49 50```bash51streamlit run app.py52 53This will start a local server and open your browser to view the app.54 55### Conclusion:56 57Streamlit is a powerful tool for building interactive data applications without the need for extensive web development skills. It's especially useful for prototyping data-driven applications and sharing insights with others in an easily digestible format.58```59 60# 🐳 Dockerfile61 62Creating a Dockerfile for a Streamlit application allows you to package your app along with its environment, making it easy to deploy and run consistently across different systems. Below is an example of a Dockerfile that sets up a Streamlit app.63 64### Example Dockerfile for Streamlit App65 66```Dockerfile67# Use the official Python image from the Docker Hub68FROM python:3.10-slim69 70# Set the working directory in the container71WORKDIR /app72 73# Copy the requirements.txt file to the container74COPY requirements.txt .75 76# Install the dependencies77RUN pip install --no-cache-dir -r requirements.txt78 79# Copy the rest of your application code to the container80COPY . .81 82# Expose the port that Streamlit runs on83EXPOSE 850184 85# Command to run the Streamlit app86CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]87```88 89### Additional Files90 911. **requirements.txt**:92   Make sure you have a `requirements.txt` file that includes all the necessary libraries your Streamlit app needs. Here’s a simple example:93 94   ```95   streamlit96   pandas97   numpy98   matplotlib99   ```100 1012. **app.py**:102   This is your main Streamlit application file that contains your Streamlit code.103 104### Building the Docker Image105 106To build a Docker image from your Dockerfile, navigate to the directory containing the Dockerfile in your terminal and run:107 108```bash109docker build -t my-streamlit-app .110```111 112### Running the Docker Container113 114After successfully building the image, you can run the container with:115 116```bash117docker run -p 8501:8501 my-streamlit-app118```119 120This maps port 8501 on the host to port 8501 on the container, allowing you to access the Streamlit app at `http://localhost:8501`.121 122### Summary123 124This Dockerfile sets up a streamlined environment to run your Streamlit app. It contains all required dependencies and exposes the appropriate port, making it easy to deploy your application in different environments. Adjust the `requirements.txt` file as necessary to include any additional Python packages your application depends on.125 126# 🧪 (Optional) Test Locally127 128If you want to test it before uploading to Hugging Face:129docker build -t bayes-app .130docker run -p 8501:8501 bayes-app131Visit http://localhost:8501 to test it in your browser.132