Skip to content

Commit

Permalink
Changes made for streamlit
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyShrestha committed Jun 7, 2024
1 parent ab17c3b commit 92d9cf1
Show file tree
Hide file tree
Showing 12 changed files with 761 additions and 519 deletions.
151 changes: 110 additions & 41 deletions Website/app.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,115 @@
import streamlit as st
import pages as pg
from streamlit_navigation_bar import st_navbar
from streamlit_option_menu import option_menu
import os
import base64

# Set page config
st.set_page_config(page_title="My App", layout="wide", initial_sidebar_state="collapsed")

# Define pages and styles for navigation bar
pages = ["Product Perishability", "Expected Expiry of Customer Purchase", "Feature 3", "Feature 4", "Closest Supermarket"]
parent_dir = os.path.dirname(os.path.abspath(__file__))
styles = {
"nav": {"background-color": "rgb(123, 209, 146)"},
"div": {"max-width": "32rem"},
"span": {"border-radius": "0.5rem", "color": "rgb(49, 51, 63)", "margin": "0 0.125rem", "padding": "0.4375rem 0.625rem"},
"active": {"background-color": "rgba(255, 255, 255, 0.25)"},
"hover": {"background-color": "rgba(255, 255, 255, 0.35)"}
}

# Navbar at the top of the page
page = st_navbar(pages, styles=styles)

# Side option menu to possibly handle additional controls or mirrored navigation
with st.sidebar:
selected = option_menu(
menu_title="Navigate",
options=pages,
default_index=0,
icons=["calendar", "calendar-check", "gear", "gear-fill", "geo"]
# Import your pages
from pages.home import home
from pages.OCR_invoice import ocr_invoice
from pages.product_perishability import product_perishability
from pages.cust_purchase_expected_expiry import cust_purchase_expected_expiry
from pages.dynamic_pricing_streamlit import dynamic_pricing_streamlit
from pages.closest_supermarket import closest_supermarket
from pages.sentiment_analysis import sentiment_analysis
from pages.time_series import show_feature5 as time_series
# from pages.food_recommender import food_recommender as food_recommender

# Set page configuration
st.set_page_config(page_title="SpicyBytes", layout="wide", initial_sidebar_state="collapsed")

# Define the path to the logo image
root_dir = os.path.abspath(os.path.join(os.getcwd()))
logo_path = os.path.join(root_dir, 'images', 'spicy_img1.jpg')

def main():
# Add logo to the top right corner
st.markdown(
f"""
<div class="top-left-logo">
<img src="data:image/jpeg;base64,{base64.b64encode(open(logo_path, "rb").read()).decode()}" alt="Logo" width="300">
</div>
""",
unsafe_allow_html=True
)

# Custom CSS to remove space between buttons and position logo, footer always at the bottom
st.markdown(
"""
<style>
.stButton button {
margin: 0;
padding: 0px;
width: 100%;
font-size: 100px;
white-space: nowrap; // Prevents text from wrapping
overflow: hidden; // Keeps text from overflowing
text-overflow: ellipsis; // Adds an ellipsis if text overflows
}
.stColumn {
display: flex;
justify-content: center;
align-items: center;
padding: 0; // Adjusts padding to reduce space between columns
margin: 0; // Removes margin around columns
}
.top-right-logo {
position: absolute;
top: 10px;
right: 10px;
width: 100px; /* Adjust the size of the logo as needed */
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: white;
color: black;
text-align: center;
padding: 10px;
}
</style>
""",
unsafe_allow_html=True
)

# Create a single row of columns with equal width
cols = st.columns(9) # Creates 8 equally spaced columns

# Dictionary to map button names to functions
pages = {
'Home': home,
'OCR': ocr_invoice,
'Product Perishability': product_perishability,
'Customer Inventory': cust_purchase_expected_expiry,
'Dynamic Pricing': dynamic_pricing_streamlit,
'Closest Supermarket': closest_supermarket,
'Food Recommendation': sentiment_analysis,
'Sentiment Analysis': sentiment_analysis,
'Time Series Analysis': time_series
}

if 'page' not in st.session_state:
st.session_state['page'] = 'Home' # Default page

# Generate buttons and assign functions
for i, (title, func) in enumerate(pages.items()):
with cols[i]:
if st.button(title):
st.session_state['page'] = title

# Display selected page
if 'page' in st.session_state and st.session_state['page'] in pages:
pages[st.session_state['page']]()

# Copyright footer
st.markdown(
"""
<div class="footer">
&copy; 2024 SpicyBytes. All Rights Reserved.
</div>
""",
unsafe_allow_html=True
)

# Mapping functions to pages
functions = {
"Product Perishability": pg.show_feature1,
"Expected Expiry of Customer Purchase": pg.show_feature2,
"Feature 3": pg.show_feature3,
"Feature 4": pg.show_feature4,
"Closest Supermarket": pg.closest_supermarket
}

# Execute function based on selected page from navbar or sidebar
if page in functions:
functions[page]()
else:
st.error("Selected page not found")
if __name__ == "__main__":
main()
24 changes: 16 additions & 8 deletions Website/pages/OCR_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ def convert_file_to_data(file_path, mime_type):

# model= genai.GenerativeModel('gemini-pro-vision')

def show_feature6():
def ocr_invoice():
# st.set_page_config(page_title= "INVOICE-INFO EXTRACTOR")

st.header("OCR INVOICE DETAILS EXTRACTION")
st.header("Invoice Details Extraction using OCR")
# input= st.text_input("Input Prompt: ", key= "input")
uploaded_file= st.file_uploader("choose an image...", type=["jpg", "jpeg", "png"])
uploaded_file= st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
image=""
if uploaded_file is not None:
image= img.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
st.image(image, caption="Image Uploaded", use_column_width=True)

submit= st.button("Tell me about the invoice")

Expand Down Expand Up @@ -175,8 +175,16 @@ def show_feature6():
st.write(f"**Total number of products:** {data['total_products']}")
st.write(f"**Mode of Payment:** {data['mode_of_payment']}")

st.header("List of Products purchased")
st.dataframe(df_products)
st.header("Products Purchased")

if __name__ == "__main__":
show_feature6()
df_products['name'] = df_products['name'].apply(lambda x: x.title())

df_products.rename(columns={
'name': 'Product Name',
'Unit price': 'Unit Price',
'quantity': 'Quantity',
'amount': 'Amount'
}, inplace=True)


st.dataframe(df_products)
6 changes: 0 additions & 6 deletions Website/pages/__init__.py

This file was deleted.

Loading

0 comments on commit 92d9cf1

Please sign in to comment.