Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import xgboost as xgb
|
3 |
+
import pandas as pd
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
# Load the dataset
|
7 |
+
dataset = load_dataset("Ammok/hair_health")
|
8 |
+
|
9 |
+
# Convert to Pandas DataFrame for exploration
|
10 |
+
df = pd.DataFrame(dataset['train'])
|
11 |
+
|
12 |
+
# Example: Train a simple XGBoost model
|
13 |
+
X = df.drop(columns=["target_column"]) # Replace with your feature columns
|
14 |
+
y = df["target_column"] # Replace with your target column
|
15 |
+
|
16 |
+
# Train a basic XGBoost model (replace with custom model training code)
|
17 |
+
model = xgb.XGBClassifier()
|
18 |
+
model.fit(X, y)
|
19 |
+
|
20 |
+
# Function for making predictions
|
21 |
+
def predict(input_data):
|
22 |
+
data = pd.DataFrame([input_data], columns=X.columns)
|
23 |
+
prediction = model.predict(data)
|
24 |
+
return prediction[0]
|
25 |
+
|
26 |
+
# Set up Gradio interface for data exploration
|
27 |
+
def explore_data(row_number):
|
28 |
+
return df.iloc[row_number].to_dict()
|
29 |
+
|
30 |
+
# Gradio UI
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
gr.Markdown("# Hair Health Dataset Exploration")
|
33 |
+
|
34 |
+
row_number_input = gr.Number(label="Row Number")
|
35 |
+
data_output = gr.JSON(label="Row Data")
|
36 |
+
row_number_input.change(explore_data, inputs=[row_number_input], outputs=[data_output])
|
37 |
+
|
38 |
+
gr.Markdown("## Make a Prediction")
|
39 |
+
input_data = {col: gr.Number(label=col) for col in X.columns} # Adjust based on features
|
40 |
+
output = gr.Textbox(label="Prediction")
|
41 |
+
|
42 |
+
submit_button = gr.Button("Predict")
|
43 |
+
submit_button.click(predict, inputs=[input_data], outputs=[output])
|
44 |
+
|
45 |
+
demo.launch()
|