**************************************************************************************************

StreamLit

**************************************************************************************************

$ pip install streamlit

# Import convention

import streamlit as st


streamlit run app.py --server.runOnSave true




Streamlit


https://docs.streamlit.io/library/cheatsheet


https://cheat-sheet.streamlit.app/



https://streamlit.io/gallery



**************************************************************************************************

Deploy in Amazon SageMaker Studio

**************************************************************************************************


You can access the app in a new browser tab using a URL that is similar to your Studio domain URL.

For example, if your Studio URL is

https://d-randomidentifier.studio.us-east-1.sagemaker.aws/jupyter/default/lab? then the URL for your Streamlit app will be

https://d-randomidentifier.studio.us-east-1.sagemaker.aws/jupyter/default/proxy/8501/webapp


(notice that lab is replaced with proxy/8501/webapp). If the port number noted in the previous step is different from 8501 then use that instead of 8501 in the URL for the Streamlit app.





https://aws.amazon.com/blogs/machine-learning/build-streamlit-apps-in-amazon-sagemaker-studio/


https://github.com/aws/amazon-sagemaker-examples/tree/main/aws_sagemaker_studio/streamlit_demo



https://aws.amazon.com/blogs/machine-learning/build-a-powerful-question-answering-bot-with-amazon-sagemaker-amazon-opensearch-service-streamlit-and-langchain/



https://aws.amazon.com/blogs/machine-learning/call-an-amazon-sagemaker-model-endpoint-using-amazon-api-gateway-and-aws-lambda/


**************************************************************************************************

Deploy in ECS-Fargate

**************************************************************************************************



https://youtu.be/Jc5GI3v2jtE


Dockerfile

    from python:3.9.0

    expose 8501

    cmd mkdir -p /app

    WORKDIR /app

    copy requirements.txt ./requirements.txt

    run pip3 install -r requirements.txt

    copy . .

    ENTRYPOINT ["streamlit", "run"]

    CMD ["main.py"]



https://github.com/rsarosh/streamlit


AWS

    Down load the AWS CLI https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html


build the image

    docker build -f Dockerfile -t streamlit-app:latest .


tag the image

    docker tag streamlit-app:latest public.ecr.aws/e3w4k9h3/streamlit:latest


Push the image

    docker push public.ecr.aws/e3w4k9h3/streamlit-app:latest


--------

import streamlit as st

from streamlit_option_menu import option_menu

from options.capture import captureData

from options.menu import menu

from options.data import showData


# Add custom CSS for styling

st.markdown("""

   <style>

   .icon { color: orange !important; font-size: 25px !important; }

   .nav-link { font-size: 25px !important; text-align: left !important; margin: 0px !important; }

   .nav-link:hover { background-color: #eee !important; }

   .nav-link-selected { background-color: blue !important; }

   </style>

""", unsafe_allow_html=True)


# Create the horizontal menu

selected = option_menu(

   menu_title=None# Hide the title if not needed

   options=["Capture Metadata","Food Metadata", "Personalized menu"],

   icons=["camera","database", "patch-check-fill"],

   menu_icon="cast",

   default_index=0,

   orientation="horizontal"

)


# Navigate to the selected page

if selected == "Capture Metadata":

   captureData()

elif selected == "Food Metadata":

   showData()

elif selected == "Personalized menu":

   menu()

-----------------

import streamlit as st

import pandas as pd

import numpy as np

def captureData():

   # Step 1: Upload a food image

   st.title("Food Information Capture App")

   uploaded_file = st.file_uploader("Upload a photo of the food", type=["jpg", "jpeg", "png"])


   if uploaded_file:

       st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)

      

       # Step 2: Make a call to the Lambda function

       if st.button('Analyze Image'):

           # You would replace this URL with your actual Lambda function's endpoint

           lambda_url = "https://your-lambda-function-url.amazonaws.com/your-endpoint"

           files = {'file': uploaded_file.getvalue()}

          

           # Call the Lambda function

           response = requests.post(lambda_url, files=files)

          

           if response.status_code == 200:

               data = response.json()

              

               # Step 3: Display the returned data in a table format and make it editable

               st.subheader("Food Information")

               df = pd.DataFrame([data])

               edited_df = st.experimental_data_editor(df# Editable table

              

               # Step 4: Append data to a CSV file

               if st.button('Save Data'):

                   edited_df.to_csv('food_data.csv', mode='a', header=False, index=False)

                   st.success("Data appended to food_data.csv")

           else:

               st.error("Failed to get data from Lambda function.")

      

----

import streamlit as st

import pandas as pd


def showData():

   # Read the CSV file

   df = pd.read_csv('food_data.csv')


   # Streamlit app

   st.title("My Food Data Table")


   # Display the DataFrame in a nice table format

   st.dataframe(df)



------

import streamlit as st

import pandas as pd

import numpy as np

import streamlit as st

import matplotlib.pyplot as plt

import numpy as np

def menu():

   # Define options for dropdowns

   event_types = ['Wedding', 'Birthday', 'Corporate Event', 'Anniversary', 'Other']

   cuisines = ['Italian', 'Chinese', 'Indian', 'Mexican', 'American', 'Other']

   meal_types = ['Buffet', 'Sit-down', 'Family Style', 'Cocktail Style']

   menu_styles = ['Traditional', 'Modern', 'Fusion']

   dietary_restrictions = ['None', 'Vegetarian', 'Vegan', 'Gluten-Free', 'Nut-Free', 'Halal', 'Kosher', 'Other']

   alcoholic_beverages = ['Yes', 'No']

   non_alcoholic_beverages = ['Yes', 'No']


   # Layout with columns

   left_column, right_column = st.columns([3, 1])  # Adjust the width ratio of columns


   with left_column:

       st.write("Please fill in the details for your event below:")

      

       with st.expander("Event Details", expanded=True):

           event_name = st.text_input("Event Name")

           event_date = st.date_input("Event Date")

           number_of_guests = st.number_input("Number of Guests", min_value=1, step=1)

           event_type = st.selectbox("Type of Event", event_types)

      

       with st.expander("Menu Preferences"):

           preferred_cuisine = st.selectbox("Preferred Cuisine", cuisines)

           meal_type = st.selectbox("Meal Type", meal_types)

           menu_style = st.selectbox("Menu Style", menu_styles)

           dietary_restriction = st.multiselect("Dietary Restrictions", dietary_restrictions)

           special_requests = st.text_area("Special Requests")

           total_budget = st.number_input("Total Budget", min_value=0.0, step=100.0)

      

       if st.button("Personalized menu"):

           st.write(f"I want to order food for **{event_name}** on **{event_date}** for **{number_of_guests}** guests. "

                   f"This event is a **{event_type}**, and I would like to serve **{preferred_cuisine}** cuisine with **{meal_type}** style, "

                   f"preferably in **{menu_style}**. There are **{', '.join(dietary_restriction) if dietary_restriction else 'no'}** dietary restrictions to consider, "

                   f"and I’d like to include **{special_requests if special_requests else 'no special requests'}**. My budget for this event is **${total_budget}**.")


   with right_column:

       st.write("## Results")

       # Placeholder for any additional results or actions

       st.write("- Result 1")

       st.write("- Result 2")

id,Food Name,Ingredients,Popular in Countries,Popular in Events,Popular in Weather,Food Temperature,Allergens,Dietary Preferences/Restrictions,Calories,Funfact/Inspiring Quote

1,Pizza,"Dough, Cheese, Tomato, Pepperoni","Italy, USA","Parties, Family Gatherings",All Seasons,Hot,"Dairy, Gluten",Non-Vegetarian,285,The first pizza was made in Naples.

2,Sushi,"Rice, Fish, Seaweed, Soy Sauce",Japan,"Business Meetings, Celebrations",Summer,Cold,"Fish, Soy",Pescatarian,200,Sushi originated as a method of preserving fish.

3,Paella,"Rice, Seafood, Saffron, Vegetables",Spain,"Festivals, Family Gatherings",Summer,Hot,Shellfish,Pescatarian,300,Paella is traditionally cooked over an open fire.