VaneshDev commited on
Commit
56e5c72
·
verified ·
1 Parent(s): c0df1ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.linear_model import LogisticRegression
5
+ from sklearn.model_selection import train_test_split
6
+ import matplotlib.pyplot as plt
7
+ import statsmodels.api as sm
8
+ from fbprophet import Prophet
9
+
10
+ # Sample data (replace with your own usage/maintenance data)
11
+ data = {
12
+ 'equipment_id': ['Excavator', 'Crane', 'Tractor'],
13
+ 'usage_hours': [120, 140, 100],
14
+ 'idle_hours': [30, 20, 50],
15
+ 'movement_frequency': [5, 7, 3],
16
+ 'cost_per_hour': [10, 15, 12]
17
+ }
18
+
19
+ # Convert to DataFrame
20
+ df = pd.DataFrame(data)
21
+
22
+ # Function to make predictions (Logistic Regression)
23
+ def model_prediction(equipment_id, usage_hours, idle_hours, movement_frequency, cost_per_hour):
24
+ # Model input
25
+ features = np.array([usage_hours, idle_hours, movement_frequency, cost_per_hour]).reshape(1, -1)
26
+
27
+ # Train a simple logistic regression model (replace with your own trained model)
28
+ model = LogisticRegression()
29
+ X = df[['usage_hours', 'idle_hours', 'movement_frequency', 'cost_per_hour']]
30
+ y = [0, 1, 0] # Dummy labels (0 = Repair, 1 = Move)
31
+ model.fit(X, y)
32
+
33
+ # Predict the suggestion
34
+ prediction = model.predict(features)[0]
35
+
36
+ # Define the suggestions
37
+ suggestions = {0: 'Repair', 1: 'Move'}
38
+
39
+ # Get confidence score
40
+ confidence = model.predict_proba(features)[0][prediction] * 100
41
+
42
+ # Return the result
43
+ return f"Suggestion: {suggestions[prediction]}\nConfidence: {confidence:.2f}%"
44
+
45
+ # Gradio Interface
46
+ interface = gr.Interface(
47
+ fn=model_prediction,
48
+ inputs=[
49
+ gr.Dropdown(choices=df['equipment_id'].tolist(), label="Select Equipment"),
50
+ gr.Number(label="Usage Hours"),
51
+ gr.Number(label="Idle Hours"),
52
+ gr.Number(label="Movement Frequency"),
53
+ gr.Number(label="Cost per Hour")
54
+ ],
55
+ outputs="text"
56
+ )
57
+
58
+ # Launch Gradio interface
59
+ interface.launch()