anoopreddyyeddula commited on
Commit
4dd3e99
·
0 Parent(s):

Initial commit

Browse files
Files changed (5) hide show
  1. README.md +26 -0
  2. app.py +40 -0
  3. data/sales_data_large.csv +0 -0
  4. requirements.txt +6 -0
  5. train_model.py +25 -0
README.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Real-Time Inventory Advisor
3
+ emoji: 📦
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 4.7.1
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # Real-Time Inventory Management System
13
+
14
+ This app predicts upcoming sales for each product and generates restocking advice powered by Machine Learning and Generative AI.
15
+
16
+ ## Features
17
+ - Product-specific sales prediction
18
+ - AI-powered restocking recommendations
19
+ - Real-time inventory management
20
+ - User-friendly interface
21
+
22
+ ## How to Use
23
+ 1. Enter Product ID
24
+ 2. Input Current Inventory
25
+ 3. Provide Yesterday's Sales
26
+ 4. Get AI-generated restocking advice
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+ from transformers import pipeline
5
+
6
+ # Load all ML models
7
+ product_models = joblib.load('models/inventory_forecaster.pkl')
8
+ llm = pipeline("text2text-generation", model="google/flan-t5-base")
9
+
10
+ # Function to predict and generate restocking advice
11
+ def inventory_advisor(product_id, current_inventory, last_day_sales):
12
+ # Select correct model
13
+ if product_id not in product_models:
14
+ return f"❌ Error: Product ID {product_id} not found in models."
15
+
16
+ forecast_model = product_models[product_id]
17
+ future_sales = forecast_model.predict([[last_day_sales]])[0]
18
+
19
+ prompt = (f"Current inventory is {current_inventory} units. "
20
+ f"Predicted sales for next week is {int(future_sales)} units. "
21
+ f"Should restocking be done? Suggest a human-readable restocking advice.")
22
+
23
+ response = llm(prompt, max_length=100)[0]['generated_text']
24
+
25
+ return f"🔮 Predicted Sales Next Week: {int(future_sales)} units\n\n🛒 Advice:\n{response}"
26
+
27
+ iface = gr.Interface(
28
+ fn=inventory_advisor,
29
+ inputs=[
30
+ gr.Number(label="Product ID"),
31
+ gr.Number(label="Current Inventory"),
32
+ gr.Number(label="Units Sold Yesterday")
33
+ ],
34
+ outputs="text",
35
+ title="📦 Real-Time Inventory Management (Multi-Product)",
36
+ description="Enter product ID, current stock, and yesterday's sales. Get AI-based restocking advice!"
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ iface.launch()
data/sales_data_large.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ scikit-learn
4
+ joblib
5
+ transformers
6
+ torch
train_model.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from sklearn.linear_model import LinearRegression
3
+ import joblib
4
+ import os
5
+
6
+ os.makedirs('models', exist_ok=True)
7
+ os.makedirs('data', exist_ok=True)
8
+
9
+ data = pd.read_csv('data/sales_data_large.csv')
10
+
11
+ product_models = {}
12
+
13
+ for product_id, group in data.groupby('Product_ID'):
14
+ group = group.sort_values('Date')
15
+ X = group[['Units_Sold']].shift(1).fillna(0)
16
+ y = group['Units_Sold']
17
+
18
+ model = LinearRegression()
19
+ model.fit(X, y)
20
+
21
+ product_models[product_id] = model
22
+
23
+ joblib.dump(product_models, 'models/inventory_forecaster.pkl')
24
+
25
+ print(f"✅ Trained and saved models for {len(product_models)} products!")