sehaj13 commited on
Commit
da7c5eb
·
verified ·
1 Parent(s): 5e3e049

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -32
app.py CHANGED
@@ -1,48 +1,114 @@
1
- # import tensorflow as tf
2
-
3
  import gradio as gr
4
  import numpy as np
 
5
  import joblib
6
 
7
- # Load your trained model
8
  model = joblib.load("mixing_prediction_model.pkl")
 
 
9
 
10
- # Prediction function
11
- def predict(COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI):
12
- features = np.array([[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI]])
13
- # pred = model.predict(features)[0]
14
- # mixing_name = le.inverse_transform([pred])[0]
15
- prediction = model.predict(features)[0][0]
16
- return prediction
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- # Gradio app with custom sliders
19
  with gr.Blocks() as demo:
20
- gr.Markdown("## 🧵 Textile Mixing Predictor (TensorFlow Model)")
21
- gr.Markdown("Adjust the sliders for each feature and get the predicted output.")
22
 
23
  with gr.Row():
24
  with gr.Column():
25
- COUNT = gr.Slider(minimum=7, maximum=50, step=0.5, label="COUNT")
26
- COUNT_CV = gr.Slider(minimum=0.48, maximum=1.87, step=0.1, label="COUNT_CV")
27
- STRENGTH = gr.Slider(minimum=62.71, maximum=384.2, step=0.1, label="STRENGTH")
28
- with gr.Column():
29
- CSP = gr.Slider(minimum=1500, maximum=4755, step=1, label="CSP")
30
- U_PERCENT = gr.Slider(minimum=6.38, maximum=12.12, step=0.1, label="U_PERCENT")
31
- THIN = gr.Slider(minimum=0.0, maximum=19, step=0.1, label="THIN")
32
  with gr.Column():
33
- THICK = gr.Slider(minimum=2.0, maximum=150, step=1, label="THICK")
34
- NEPS = gr.Slider(minimum=1, maximum=494, step=1, label="NEPS")
35
- IPI = gr.Slider(minimum=6.0, maximum=646, step=1, label="IPI")
 
 
36
 
37
- output = gr.Number(label="Predicted Output")
38
 
39
- predict_button = gr.Button("Predict")
40
-
41
- # Bind inputs to function
42
- predict_button.click(
43
- fn=predict,
44
- inputs=[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI],
45
- outputs=output
46
- )
47
 
48
  demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import numpy as np
3
+ import pandas as pd
4
  import joblib
5
 
6
+ # Load model and preprocessing objects
7
  model = joblib.load("mixing_prediction_model.pkl")
8
+ scaler = joblib.load("scaler.pkl")
9
+ label_encoder = joblib.load("label_encoder.pkl")
10
 
11
+ # Define prediction function
12
+ def predict_class(COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI):
13
+ # Input as a DataFrame with correct feature names
14
+ input_df = pd.DataFrame([{
15
+ "COUNT": COUNT,
16
+ "COUNT_CV": COUNT_CV,
17
+ "STRENGTH": STRENGTH,
18
+ "CSP": CSP,
19
+ "U_PERCENT": U_PERCENT,
20
+ "THIN": THIN,
21
+ "THICK": THICK,
22
+ "NEPS": NEPS,
23
+ "IPI": IPI
24
+ }])
25
+
26
+ # Scale input
27
+ scaled_input = scaler.transform(input_df)
28
+
29
+ # Predict
30
+ pred_index = model.predict(scaled_input)[0]
31
+
32
+ # Decode class label
33
+ predicted_label = label_encoder.inverse_transform([pred_index])[0]
34
+
35
+ return predicted_label
36
 
37
+ # Build Gradio Interface
38
  with gr.Blocks() as demo:
39
+ gr.Markdown("## 🧵 Textile Mixing Classifier (Scikit-learn Model)")
40
+ gr.Markdown("Use the sliders to set values and click **Predict** to classify the textile mix.")
41
 
42
  with gr.Row():
43
  with gr.Column():
44
+ COUNT = gr.Slider(7, 50, step=0.5, label="COUNT")
45
+ COUNT_CV = gr.Slider(0.48, 1.87, step=0.1, label="COUNT_CV")
46
+ STRENGTH = gr.Slider(62.71, 384.2, step=0.1, label="STRENGTH")
47
+ CSP = gr.Slider(1500, 4755, step=1, label="CSP")
 
 
 
48
  with gr.Column():
49
+ U_PERCENT = gr.Slider(6.38, 12.12, step=0.1, label="U_PERCENT")
50
+ THIN = gr.Slider(0.0, 19, step=0.1, label="THIN")
51
+ THICK = gr.Slider(2.0, 150, step=1, label="THICK")
52
+ NEPS = gr.Slider(1, 494, step=1, label="NEPS")
53
+ IPI = gr.Slider(6.0, 646, step=1, label="IPI")
54
 
55
+ output = gr.Textbox(label="Predicted Class")
56
 
57
+ btn = gr.Button("Predict")
58
+ btn.click(fn=predict_class,
59
+ inputs=[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI],
60
+ outputs=output)
 
 
 
 
61
 
62
  demo.launch()
63
+
64
+
65
+
66
+
67
+ # import tensorflow as tf
68
+
69
+ # import gradio as gr
70
+ # import numpy as np
71
+ # import joblib
72
+
73
+ # # Load your trained model
74
+ # model = joblib.load("mixing_prediction_model.pkl")
75
+
76
+ # # Prediction function
77
+ # def predict(COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI):
78
+ # features = np.array([[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI]])
79
+ # # pred = model.predict(features)[0]
80
+ # # mixing_name = le.inverse_transform([pred])[0]
81
+ # prediction = model.predict(features)[0][0]
82
+ # return prediction
83
+
84
+ # # Gradio app with custom sliders
85
+ # with gr.Blocks() as demo:
86
+ # gr.Markdown("## 🧵 Textile Mixing Predictor (TensorFlow Model)")
87
+ # gr.Markdown("Adjust the sliders for each feature and get the predicted output.")
88
+
89
+ # with gr.Row():
90
+ # with gr.Column():
91
+ # COUNT = gr.Slider(minimum=7, maximum=50, step=0.5, label="COUNT")
92
+ # COUNT_CV = gr.Slider(minimum=0.48, maximum=1.87, step=0.1, label="COUNT_CV")
93
+ # STRENGTH = gr.Slider(minimum=62.71, maximum=384.2, step=0.1, label="STRENGTH")
94
+ # with gr.Column():
95
+ # CSP = gr.Slider(minimum=1500, maximum=4755, step=1, label="CSP")
96
+ # U_PERCENT = gr.Slider(minimum=6.38, maximum=12.12, step=0.1, label="U_PERCENT")
97
+ # THIN = gr.Slider(minimum=0.0, maximum=19, step=0.1, label="THIN")
98
+ # with gr.Column():
99
+ # THICK = gr.Slider(minimum=2.0, maximum=150, step=1, label="THICK")
100
+ # NEPS = gr.Slider(minimum=1, maximum=494, step=1, label="NEPS")
101
+ # IPI = gr.Slider(minimum=6.0, maximum=646, step=1, label="IPI")
102
+
103
+ # output = gr.Number(label="Predicted Output")
104
+
105
+ # predict_button = gr.Button("Predict")
106
+
107
+ # # Bind inputs to function
108
+ # predict_button.click(
109
+ # fn=predict,
110
+ # inputs=[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI],
111
+ # outputs=output
112
+ # )
113
+
114
+ # demo.launch()