File size: 4,031 Bytes
5df391c
be39351
da7c5eb
be39351
5df391c
da7c5eb
0254e9a
da7c5eb
0254e9a
5df391c
da7c5eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5df391c
da7c5eb
5df391c
da7c5eb
 
5df391c
a4ac773
 
da7c5eb
 
 
a4ac773
da7c5eb
 
 
a4ac773
da7c5eb
 
 
5df391c
da7c5eb
5df391c
da7c5eb
 
 
 
5df391c
 
da7c5eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import gradio as gr
import numpy as np
import pandas as pd
import joblib

# Load model and preprocessing objects
model = joblib.load("model.pkl")
scaler = joblib.load("scaler.pkl")
label_encoder = joblib.load("label_encoder.pkl")

# Define prediction function
def predict_class(COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI):
    # Input as a DataFrame with correct feature names
    input_df = pd.DataFrame([{
        "COUNT": COUNT,
        "COUNT_CV": COUNT_CV,
        "STRENGTH": STRENGTH,
        "CSP": CSP,
        "U_PERCENT": U_PERCENT,
        "THIN": THIN,
        "THICK": THICK,
        "NEPS": NEPS,
        "IPI": IPI
    }])
    
    # Scale input
    scaled_input = scaler.transform(input_df)
    
    # Predict
    pred_index = model.predict(scaled_input)[0]
    
    # Decode class label
    predicted_label = label_encoder.inverse_transform([pred_index])[0]
    
    return predicted_label

# Build Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("## 🧵 Textile Mixing Classifier (Scikit-learn Model)")
    gr.Markdown("Use the sliders to set values and click **Predict** to classify the textile mix.")

    with gr.Column():
        with gr.Row():
            COUNT = gr.Slider(7, 50, step=0.5, label="COUNT")
            COUNT_CV = gr.Slider(0.48, 1.87, step=0.1, label="COUNT_CV")
            STRENGTH = gr.Slider(62.71, 384.2, step=0.1, label="STRENGTH")
        with gr.Row():
            CSP = gr.Slider(1500, 4755, step=1, label="CSP")
            U_PERCENT = gr.Slider(6.38, 12.12, step=0.1, label="U_PERCENT")
            THIN = gr.Slider(0.0, 19, step=0.1, label="THIN")
        with gr.Row():
            THICK = gr.Slider(2.0, 150, step=1, label="THICK")
            NEPS = gr.Slider(1, 494, step=1, label="NEPS")
            IPI = gr.Slider(6.0, 646, step=1, label="IPI")

    output = gr.Textbox(label="Predicted Class")

    btn = gr.Button("Predict")
    btn.click(fn=predict_class,
              inputs=[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI],
              outputs=output)

demo.launch()




# import tensorflow as tf

# import gradio as gr
# import numpy as np
# import joblib

# # Load your trained model
# model = joblib.load("mixing_prediction_model.pkl")

# # Prediction function
# def predict(COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI):
#     features = np.array([[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI]])
#     # pred = model.predict(features)[0]
#     # mixing_name = le.inverse_transform([pred])[0]
#     prediction = model.predict(features)[0][0]
#     return prediction

# # Gradio app with custom sliders
# with gr.Blocks() as demo:
#     gr.Markdown("## 🧵 Textile Mixing Predictor (TensorFlow Model)")
#     gr.Markdown("Adjust the sliders for each feature and get the predicted output.")

#     with gr.Row():
#         with gr.Column():
#             COUNT = gr.Slider(minimum=7, maximum=50, step=0.5, label="COUNT")
#             COUNT_CV = gr.Slider(minimum=0.48, maximum=1.87, step=0.1, label="COUNT_CV")
#             STRENGTH = gr.Slider(minimum=62.71, maximum=384.2, step=0.1, label="STRENGTH")
#         with gr.Column():
#             CSP = gr.Slider(minimum=1500, maximum=4755, step=1, label="CSP")
#             U_PERCENT = gr.Slider(minimum=6.38, maximum=12.12, step=0.1, label="U_PERCENT")
#             THIN = gr.Slider(minimum=0.0, maximum=19, step=0.1, label="THIN")
#         with gr.Column():
#             THICK = gr.Slider(minimum=2.0, maximum=150, step=1, label="THICK")
#             NEPS = gr.Slider(minimum=1, maximum=494, step=1, label="NEPS")
#             IPI = gr.Slider(minimum=6.0, maximum=646, step=1, label="IPI")

#     output = gr.Number(label="Predicted Output")

#     predict_button = gr.Button("Predict")

#     # Bind inputs to function
#     predict_button.click(
#         fn=predict,
#         inputs=[COUNT, COUNT_CV, STRENGTH, CSP, U_PERCENT, THIN, THICK, NEPS, IPI],
#         outputs=output
#     )

# demo.launch()