Blog

PKU Protein Puzzle: A Containerized Streamlit Approach

21 Nov, 2024
Xebia Background Header Wave

I hope the title sparked your interested but you might still be puzzled what this blog is exactly about. Let me explain. PKU (Phenylketonuria) is a rare metabolic disorder that requires meticulous dietary planning. Those affected must adhere to a strict low-protein diet to prevent severe health issues. To raise awareness for PKU and to raise money to battle metabolic disorders I’ve created a containerized web app using Streamlit: the PKU Protein Puzzle.

PKU Protein Puzzle

To play the puzzle follow this link. To find out more about the technical details, please read on. The app contains the following components:

  • User Interface: Streamlit to provide the web interface for user interaction.
  • Core Functionality: Python logic to process the user’s input.
  • AI Integration:
    • Azure OpenAI to provides AI-generated feedback on the menu.
    • Custom prompts to guide the AI in generating useful suggestions.
  • Logging and Monitoring: Application Insights and Opentelemetry to log key metrics and monitor app usage.
  • Backend and Infrastructure:
    • Docker to containerize the app for consistent deployment across environments.
    • Azure Container Registry to store Docker images for easy access during deployment.
    • Azure Container Apps to host and scale the app in a cloud environment.
  • Automation and Deployment: Makefile to automate build, tag, push, and deployment processes.

We will dive into these topics in the next sections.

User Interface

The PKU Protein Puzzle app leverages Streamlit to easily create an interactive and user-friendly web interface. Streamlit makes it very easy to build and deploy custom web applications. There are many building blocks you can use so it is great for prototyping or simple apps.

PKU Protein Puzzle App

Core Functionality

The app provides a list of food items along with their protein content. Users can select these items and specify quantities for each meal (breakfast, lunch, and dinner). Using a table that can be edited the user can experiment with different food combinations to meet the dietary requirements for PKU.

To ensure that the daily menu adheres to PKU dietary guidelines, the app calculates the total protein amount and food weight based on user inputs. The calculations are displayed directly to provide immediate feedback. This helps users make necessary adjustments to achieve the exact protein intake required for a PKU-friendly diet.

AI Integration

The app integrates with Azure OpenAI to provide AI-generated feedback on the menu. By analyzing the selected food items and their nutritional content, the AI suggests adjustments to meet the exact dietary requirements of a PKU diet. This feature adds a bit of fun to the app. Since it is only some textual feedback it doesn’t matter that the AI is not 100% accurate (which you might notice).

Logging and Monitoring

To ensure the app runs smoothly and to track the usage, the app incorporates Azure Monitor for logging and health checks. Azure Monitor captures key metrics, such as session IDs, total protein, and food weight, and whether AI feedback was requested. This real-time monitoring allows for quick identification and resolution of any issues, ensuring a reliable user experience.

Below you see an example query with which I can get some insights into the number of people that played the game and what, for example, the average protein amount was.

Queried logs

Backend and Infrastructure

The app is containerized using Docker, which ensures consistent deployment across different environments. Docker simplifies the process of building, shipping, and running applications by packaging the app and its dependencies into a container. This approach eliminates the “it works on my machine” problem, providing a consistent runtime environment. You can test it on your own laptop and then deploy it to Azure when you are ready.

The Docker images are stored in Azure Container Registry and the app is deployed as an Azure Container App. Azure Container Apps provides a serverless container experience, enabling the app to scale based on demand and only pay if the app is used.

Automation and Deployment

A Makefile is used to automate the build, tag, push, and deployment processes. This automation ensures that it is easy to keep the app up-to-date and minimizes the risk of manual mistakes.

As a result it is easy to locally run and test the container on your own laptop and automatically deploy it when you are happy with the changes.

Wrap up

I’ve built this app as a fun project for a serious cause. If you liked it please consider to donate here.

For the code and setup instructions, please refer to the GitHub repository here.

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts