TA Session 19 August: Streamlit, Heroku#
Duration: 1h 47m
Here’s an FAQ summary of the live tutorial:
Q1: What is Streamlit and why should I use it for deploying applications? (0:16, 2:03, 2:45)
A1: Streamlit is an application that allows you to quickly and easily create and deploy interactive web applications. If you’ve developed an application and want customers to use and interact with it, Streamlit offers a “happy middle ground” compared to other methods. You avoid the complexities of building a full front-end with technologies like Flask, HTML, or CSS, which is a significant undertaking. It’s very quick and easy to deploy your apps.
Q2: How does Streamlit compare to other methods like Google Colab or building a full front-end? (0:48, 1:31, 2:45)
A2:
- Google Colab: While useful for notebooks with markdown and various cells, it’s not overly user-friendly for non-technical users or for deploying a full application. It’s better if the user has some technical knowledge, but has limitations in presentation. Streamlit runs the whole application in a single go, unlike Colab’s independent cells.
- Full Front-end (e.g., Flask with Jinja, HTML, CSS): This offers a very good interactive system, custom-built for your customers. However, it requires enormous resources and effort to develop.
- Streamlit: It provides an interactive and reactive front-end that connects to your application, handles processing, and produces results for users. It’s much faster and requires fewer resources to deploy compared to building a full front-end, making it ideal for rapid prototyping and mockups.
Q3: What are the main advantages of Streamlit? (2:45, 18:11, 20:00)
A3: Streamlit’s core strength is speed and simplicity. You can create a fully functional, interactive, and reactive web application with just a few lines of Python code, without needing to write separate HTML, CSS, or JavaScript. It automatically generates the necessary front-end components. It’s excellent for rapid prototyping, getting quick mockups for stakeholders, and iterating quickly on application ideas.
Q4: What about Power BI and other tools like Excel or Google Sheets? (3:13, 4:02)
A4: Power BI is a Microsoft application primarily used for creating quick graphs and data visualizations faster than manual methods like Excel. However, it’s proprietary and many features are behind a paywall, so we won’t cover it in depth. Excel and Google Sheets offer similar capabilities for storytelling and creating charts/tables, but are generally less integrated for application deployment compared to Streamlit.
Q5: What is data anonymization and why is it important? (5:17, 5:55)
A5: Data anonymization is the process of modifying data to protect individual privacy. It’s crucial due to legal regulations, especially in regions like the West (and to a lesser extent, India), to prevent identifying individuals from the data. It’s an important aspect of processing data before creating and displaying results.
Q6: What are K-anonymity and L-diversity? (6:35, 11:07)
A6:
- K-anonymity: This means that in an anonymized dataset, each record is indistinguishable from at least (K-1) other records. For example, if K=10, your record cannot be uniquely identified among at least 9 others. The goal is to make it harder to link specific individuals to data.
- L-diversity: This concept addresses limitations of K-anonymity, especially when dealing with sensitive attributes where K-anonymity alone might not prevent re-identification. (The tutorial does not go into detail for L-diversity, focusing on familiarity with the term.) You should be familiar with the basic concepts and what these terms mean for the end-term exam.
Q7: What are quasi-identifiers and how do they pose a risk to privacy? (9:23, 10:13)
A7:
- Primary attributes: These are directly identifying pieces of information (e.g., your username).
- Quasi-identifiers (or quasi-attributes): These are pieces of information that, while not directly identifying on their own, can be combined with other publicly available data to uniquely identify an individual. Examples include postcode, age, gender, or details about an online degree. The risk is that even if primary identifiers are removed or anonymized (e.g., K-anonymity), someone could combine quasi-identifiers from the anonymized dataset with other external information (metadata) to “reverse” the anonymization and identify you, especially in small populations.
Q8: What tools and setup are required to use Streamlit? (11:50, 13:16)
A8:
- Editor: An integrated development environment (IDE) or text editor like Visual Studio Code (VS Code) is recommended.
- Python Environment: Use a virtual environment (
.venv) for your project. - Python Package: Install Streamlit (
pip install streamlit). - Version Control: A GitHub account is necessary for deployment.
- Deployment Platform: Heroku account is required to deploy your application.
Q9: Why can’t I use Google Colab for Streamlit application development? (11:53)
A9: Streamlit applications are designed to run as a single, cohesive unit. Google Colab executes code cell by cell, meaning cells run independently. This architecture is incompatible with how Streamlit needs to operate, which requires the entire application to be built and run in a single process. Therefore, a proper code editor like VS Code is necessary.
Q10: What’s the basic process to create a Streamlit app? (13:34, 17:36)
A10:
- Setup: Create a project folder, initialize a Git repository (
git init), set up a virtual environment, and install Streamlit (pip install streamlit). Configure a.gitignorefile to exclude your virtual environment from version control. - Code: Create a Python file (e.g.,
app.py). Import Streamlit (import streamlit as st). - Add Content: Use Streamlit functions like
st.title("Your App Title")to add a title,st.sidebarfor a sidebar, and various widgets likest.text_input,st.slider,st.checkbox,st.radioto get user input or display information. - Logic: Implement Python code to process user input and perform transformations.
- Display: Use
st.write()to display results. Markdown can be used directly withinst.write()for rich formatting. - Run Locally: Open your terminal in the project directory and execute
streamlit run app.py. Streamlit apps support hot reloading, so changes in your code are immediately reflected in the browser without restarting the server.
Q11: Where can I find more detailed documentation for Streamlit? (20:03)
A11: The official Streamlit documentation at docs.streamlit.io is an excellent resource. You’ll find an API reference that details all available functions and widgets, how to use markdown, input widgets, and tutorials. The documentation is known for being comprehensive and includes examples.
Q12: What is Heroku and why use it for deployment? (22:00, 22:23)
A12: Heroku is a Platform-as-a-Service (PaaS) that provides virtual containers/web servers to host your applications. It makes your application accessible worldwide (deployable). Key benefits include scalability (it can scale resources up or down based on demand), and it operates on a pay-as-you-go model. You don’t manage the underlying infrastructure; Heroku handles it for you.
Q13: What files are needed for Streamlit deployment on Heroku? (23:00, 24:00, 25:00, 26:00)
A13: You need three specific files in your project’s root directory:
Procfile: This file tells Heroku what command to run to start your web server (e.g.,web: sh setup.sh && streamlit run app.py).requirements.txt: This file lists all the Python dependencies your application needs. It’s usually generated usingpip freeze > requirements.txt.setup.sh: This is a Bash script that Heroku runs before starting your Streamlit application. It performs necessary setup tasks, such as creating the.streamlitdirectory and populatingcredentials.tomlandconfig.tomlfiles, which Streamlit requires for server-side operation in a headless environment.
Q14: What is the overall process for deploying a Streamlit app to Heroku? (27:00, 27:00)
A14:
- Prepare Files: Ensure your
app.py,Procfile,requirements.txt, andsetup.shfiles are correctly configured in your project root. - GitHub: Push your entire project to a public GitHub repository.
- Heroku App Creation: Log into Heroku, create a new app, and specify a unique name and region.
- Connect to GitHub: Link your Heroku app to your GitHub repository.
- Deploy: Initiate a manual deployment from Heroku. Heroku will automatically install dependencies, run your
setup.shscript, and start your Streamlit application. - Access: Once deployed, Heroku provides a public URL for your web application.
Q15: What kind of questions can I expect for Streamlit in the end-term exam? (31:00)
A15: Expect basic questions focusing on Streamlit’s functionality and purpose. Examples include:
- “What Streamlit command is used to add text to the app interface?” (Answer:
st.write()orst.text()) - “What is the purpose of
st.button()command in a Streamlit app?” - Questions won’t be overly complex, but you should be familiar with the basic commands and how they function. Hands-on practice is recommended.
Q16: What kind of questions can I expect for data anonymization in the end-term exam? (32:00)
A16: Questions will revolve around the concepts of privacy and data anonymization. Examples include:
- “What is K-anonymity?”
- “What are quasi-identifiers?”
- “What is SaaS (Software as a Service)?” (Heroku is a PaaS, but SaaS is a related concept that might be tested.) These will also be foundational questions that test your understanding of the core definitions and purposes.
Q17: Will there be a mock exam for the end-term? (36:00)
A17: It is unlikely there will be a mock exam for this term, as the responsible professor is currently unavailable. However, PYQs (Previous Year Questions) and the provided demo form serve as good preparation materials.
Q18: Should I do PYQs (Previous Year Questions) to prepare for the end-term? (39:00)
A18: Yes, PYQs are highly recommended. They are good examples of the structure and types of questions you can expect. However, be aware that while the topics in PYQs might be relevant, the specific content will reflect this term’s material. The demo form provided in the tutorial is a good representation of what the questions for this term will look like.
Q19: What is the general strategy for taking the TDS end-term exam? (40:00)
A19: The TDS exam is very practical. The questions are direct, and you either know the answer or you don’t. A recommended strategy is to tackle the TDS questions first. They are typically quick to answer, allowing you to finish that section rapidly (historically, students can finish within 15-20 minutes). This frees up more time for your other subjects in the exam. Rote learning (“rattamaarna”) won’t work; you need to understand the concepts.
Q20: What happened with the P2 Streamlit submission that showed a “wrong answer” even for correct solutions? (36:00)
A20: The instructor confirmed that there was no issue with the script itself. It was designed to indicate a “wrong answer” if any part of the submission was incorrect, without specifying which part. This design choice was intended to prevent students from identifying specific errors easily. The instructor has raised this feedback with the technical team and is awaiting an official update.
Q21: Was the last question on the PYQ form (KMeans) a Multiple Choice Question (MCQ) or Multiple Select Question (MSQ)? (42:00, 45:00)
A21: The last question on the PYQ form was intended to be an MSQ (Multiple Select Question), meaning multiple options could be correct. The instructor checked and confirmed it was configured as such.
Q22: As a student, what should I practice with Streamlit? (35:00, 46:00)
A22: Practice creating simple Streamlit applications. The instructor created a basic app in 15-16 lines of code during the tutorial. You should aim to do the same, making working demos to understand how it functions. Use the Streamlit documentation as a guide. Don’t just read about it; actively code.
Note: The instructor mentioned Heroku as SaaS initially but later clarified that it is PaaS (Platform as a Service). This correction is included in the relevant FAQ entry.
