CoolFace
Apppublic

sachee123/Human_Activity_Recognition_Verifier

sourceHugging Faceapache-2.0updated 8mo agoView on Hugging Face
0likes
app.py71 linesDownload Raw Back to root
1import gradio as gr
2import joblib
3import numpy as np
4from sklearn.metrics import accuracy_score, classification_report
5
6# Global variables
7pipeline = None
8X_test_saved = None
9Y_test_saved = None
10
11def load_model_and_data():
12    global pipeline, X_test_saved, Y_test_saved
13    
14    X_test_saved = np.loadtxt('X_test_data.csv', delimiter=',')
15    Y_test_saved = np.loadtxt('Y_test_data.csv', delimiter=',')
16    pipeline = joblib.load('mlp_pipeline.joblib')
17    
18    result = []
19    result.append("✅ SUCCESS! Model & Data Loaded!")
20    result.append("Data: " + str(X_test_saved.shape) + ", " + str(Y_test_saved.shape))
21    result.append("First sample: " + str(X_test_saved[0, :5]))
22    result.append("Model Ready! Click VERIFY")
23    return "\n".join(result)
24
25def verify_model():
26    global pipeline, X_test_saved, Y_test_saved
27    
28    if pipeline is None:
29        return "❌ Click START first"
30    
31    y_pred = pipeline.predict(X_test_saved)
32    accuracy = accuracy_score(Y_test_saved, y_pred)
33    report = classification_report(Y_test_saved, y_pred)
34    
35    sample_preds = ""
36    for i in range(10):
37        status = "✅" if Y_test_saved[i] == y_pred[i] else "❌"
38        sample_preds += "True: " + str(Y_test_saved[i]) + ", Pred: " + str(y_pred[i]) + " " + status + "\n"
39    
40    result = []
41    result.append("ACCURACY: " + str(round(accuracy*100, 1)) + "%")
42    result.append("Classification Report:")
43    result.append(report)
44    result.append("First 10 Predictions:")
45    result.append(sample_preds)
46    return "\n".join(result)
47
48# Updated layout - Buttons in 2 rows, larger results
49with gr.Blocks(title="Activity Recognition") as demo:
50    gr.Markdown("# 🏃‍♂️ Human Activity Recognition Verifier")
51    
52    # Button row 1
53    start_btn = gr.Button("▶️ START (Load Model + Data)", variant="primary", scale=1)
54    
55    # Button row 2  
56    verify_btn = gr.Button("✅ VERIFY Model Performance", variant="secondary", scale=1)
57    
58    # Large results window
59    result_box = gr.Textbox(
60        label="Model Verification Results", 
61        lines=35, 
62        max_lines=40,
63        scale=3
64    )
65    
66    # Connect buttons
67    start_btn.click(load_model_and_data, outputs=result_box)
68    verify_btn.click(verify_model, outputs=result_box)
69
70if __name__ == "__main__":
71    demo.launch()