Spaces:
Sleeping
Sleeping
File size: 4,306 Bytes
fc591bf | 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | import gradio as gr
import pandas as pd
from src.MLOps_Project.pipeline.prediction_pipeline import PredictionPipeline
history_data = []
def predict_quality(
fixed_acidity,
volatile_acidity,
citric_acid,
residual_sugar,
chlorides,
free_sulfur_dioxide,
total_sulfur_dioxide,
density,
pH,
sulphates,
alcohol
):
try:
input_dict = {
"fixed acidity": fixed_acidity,
"volatile acidity": volatile_acidity,
"citric acid": citric_acid,
"residual sugar": residual_sugar,
"chlorides": chlorides,
"free sulfur dioxide": free_sulfur_dioxide,
"total sulfur dioxide": total_sulfur_dioxide,
"density": density,
"pH": pH,
"sulphates": sulphates,
"alcohol": alcohol,
}
df = pd.DataFrame([input_dict])
pipeline = PredictionPipeline()
prediction = pipeline.predict(df)[0]
# Save to history
history_data.append({**input_dict, "prediction": prediction})
return f"๐ท Predicted Wine Quality: {prediction}", pd.DataFrame(history_data)
except Exception as e:
return f"โ Error: {str(e)}", pd.DataFrame(history_data)
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap');
* {
font-family: 'JetBrains Mono', monospace;
}
body, .gradio-container {
background-color: #0b0b0b !important;
}
h1, h2, h3, label {
color: #facc15 !important;
}
input, textarea {
background-color: #151515 !important;
color: white !important;
border: 1px solid #facc15 !important;
}
button {
background-color: #facc15 !important;
color: black !important;
font-weight: 600;
border-radius: 6px;
}
button:hover {
background-color: #fde047 !important;
}
.dataframe {
background-color: #0b0b0b !important;
color: white !important;
}
"""
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as app:
gr.Markdown(
"""
# ๐ท Wine Quality Prediction
### End-to-End MLOps Deployment with History Tracking
"""
)
with gr.Tabs():
with gr.Tab("๐ฎ Predict"):
with gr.Row():
with gr.Column():
fixed_acidity = gr.Number(label="Fixed Acidity")
volatile_acidity = gr.Number(label="Volatile Acidity")
citric_acid = gr.Number(label="Citric Acid")
residual_sugar = gr.Number(label="Residual Sugar")
chlorides = gr.Number(label="Chlorides")
free_sulfur_dioxide = gr.Number(label="Free Sulfur Dioxide")
with gr.Column():
total_sulfur_dioxide = gr.Number(label="Total Sulfur Dioxide")
density = gr.Number(label="Density")
pH = gr.Number(label="pH")
sulphates = gr.Number(label="Sulphates")
alcohol = gr.Number(label="Alcohol")
predict_btn = gr.Button("๐ Predict")
prediction_output = gr.Textbox(
label="Prediction Result",
interactive=False
)
with gr.Tab("๐ History"):
history_table = gr.Dataframe(
headers=[
"fixed acidity", "volatile acidity", "citric acid",
"residual sugar", "chlorides", "free sulfur dioxide",
"total sulfur dioxide", "density", "pH",
"sulphates", "alcohol", "prediction"
],
interactive=False,
wrap=True
)
predict_btn.click(
fn=predict_quality,
inputs=[
fixed_acidity,
volatile_acidity,
citric_acid,
residual_sugar,
chlorides,
free_sulfur_dioxide,
total_sulfur_dioxide,
density,
pH,
sulphates,
alcohol,
],
outputs=[prediction_output, history_table]
)
if __name__ == "__main__":
app.launch(server_name="0.0.0.0", server_port=7860)
|