snehakingrani's picture
Update app.py
88d80fe verified
import os
import streamlit as st
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
# Ensure API key is set
if not GROQ_API_KEY:
st.error("API key is missing. Please check your .env file.")
st.stop()
# Simulated Inventory Data (Replace with actual database/API in production)
inventory = {
"Panadol": {"stock": 15, "limit": 10},
"Brufen": {"stock": 20, "limit": 5},
# Antihistamines
"Rigix": {"stock": 5, "limit": 5},
"Zyrtec": {"stock": 8, "limit": 3},
# Antibiotics
"Augmentin": {"stock": 12, "limit": 6},
"Flagyl": {"stock": 18, "limit": 7},
# Respiratory Treatments
"Ventolin": {"stock": 10, "limit": 5},
# Cardiovascular Medications
"Lipitor": {"stock": 9, "limit": 4},
"Plavix": {"stock": 6, "limit": 2},
# Gastrointestinal Treatments
"Nexium": {"stock": 11, "limit": 5},
"Zantac": {"stock": 10, "limit": 4},
# Antidepressants
"Cipralex": {"stock": 7, "limit": 3},
"Zoloft": {"stock": 7, "limit": 3},
# Thyroid Medications
"Synthroid": {"stock": 13, "limit": 5},
# Antiviral Medications
"Tamiflu": {"stock": 5, "limit": 2},
# Anti-inflammatory Medications
"Voltaren": {"stock": 16, "limit": 6},
# Anti-anxiety Medications
"Xanax": {"stock": 8, "limit": 3},
# Cholesterol-Lowering Medications
"Zocor": {"stock": 12, "limit": 5},
# Creams
"Dermovate Cream": {"stock": 20, "limit": 5},
"Betnovate Cream": {"stock": 15, "limit": 5},
"Fucidin Cream": {"stock": 10, "limit": 3},
"Mupirocin Ointment": {"stock": 8, "limit": 2},
"Hydrocortisone Cream": {"stock": 12, "limit": 4},
# Vitamin Supplements
"Vitamin C Tablets": {"stock": 25, "limit": 10},
"Vitamin D3 Capsules": {"stock": 18, "limit": 7},
"Vitamin B12 Tablets": {"stock": 20, "limit": 8},
"Multivitamin Capsules": {"stock": 30, "limit": 10},
"Calcium with Vitamin D Tablets": {"stock": 22, "limit": 9},
"Omega-3 Fish Oil Capsules": {"stock": 15, "limit": 5},
"Zinc Supplements": {"stock": 17, "limit": 6},
"Iron Supplements": {"stock": 14, "limit": 5},
}
# Streamlit UI Configuration
st.set_page_config(page_title="📦 Inventory Management Chatbot", layout="wide")
st.title("📦 Inventory Management Chatbot")
st.write("Track stock levels, get restock alerts, and manage your warehouse efficiently.")
# Display Inventory Details
st.subheader("📊 Current Stock Levels")
for item, details in inventory.items():
stock = details["stock"]
limit = details["limit"]
st.write(f"**{item.capitalize()}:** {stock} units (Reorder Level: {limit} units)")
# Alert when stock reaches or falls below the reorder level
if stock <= limit:
st.warning(f"⚠️ **Low Stock Alert:** {item.capitalize()} has reached its reorder level! Consider restocking.")
st.markdown("---")
# Function to Reduce Stock
def reduce_stock(medicine_name, reduction_amount):
if medicine_name in inventory:
current_stock = inventory[medicine_name]["stock"]
new_stock = max(current_stock - reduction_amount, 0) # Prevent negative stock
inventory[medicine_name]["stock"] = new_stock
return current_stock, new_stock
else:
return None, None
# User Input for Stock Reduction
st.subheader("🔧 Update Stock Levels")
medicine_name = st.selectbox("Select Medicine to Reduce Stock:", list(inventory.keys()))
reduction_amount = st.number_input("Enter Quantity to Reduce:", min_value=1, step=1)
if st.button("Update Stock"):
before_stock, after_stock = reduce_stock(medicine_name, reduction_amount)
if before_stock is not None:
st.success(f"**{medicine_name.capitalize()}** stock reduced by {reduction_amount} units.")
st.write(f"**Previous Stock Level:** {before_stock} units")
st.write(f"**Current Stock Level:** {after_stock} units")
# Check if the new stock level is at or below the reorder level
if after_stock <= inventory[medicine_name]["limit"]:
st.warning(f"⚠️ **Low Stock Alert:** {medicine_name.capitalize()} has reached its reorder level! Consider restocking.")
else:
st.error("Invalid medicine selected.")
# Footer
st.markdown("---")
st.markdown("🔹 **Powered by Streamlit**")