File size: 6,051 Bytes
facf506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{% extends "base.html" %}
{% block title %}Predict - Data2Model{% endblock %}

{% block content %}
<div class="container my-5">
    <div class="text-center mb-4">
        <h1 class="display-4">
            <i class="fas fa-chart-line"></i> Make Predictions
        </h1>
        <p class="lead">Use your validated model to predict on new data</p>
    </div>

    <!-- Model Status Banner -->
    <div class="row mb-4">
        <div class="col-lg-8 mx-auto">
            <div class="alert alert-success d-flex align-items-center gap-3 mb-0">
                <i class="fas fa-unlock-alt fa-2x"></i>
                <div>
                    <strong>Model Ready:</strong> {{ model_state.model_name }}
                    <span class="badge bg-primary ms-2">{{ model_state.problem_type|title }}</span><br>
                    <small>Split: {{ model_state.split_info }} — trained, tested &amp; validated ✓</small>
                </div>
            </div>
        </div>
    </div>

    {% if predictions %}
    <!-- Predictions Results -->
    <div class="row mb-4">
        <div class="col-lg-10 mx-auto">
            <div class="card shadow">
                <div class="card-header bg-success text-white">
                    <h4 class="mb-0">
                        <i class="fas fa-check-circle"></i> Predictions Generated Successfully!
                    </h4>
                </div>
                <div class="card-body">
                    <p>Total predictions made: <strong>{{ predictions|length }}</strong></p>
                    
                    <div class="table-responsive mt-3">
                        <table class="table table-striped table-hover">
                            <thead class="table-dark">
                                <tr>
                                    <th>Row #</th>
                                    <th>Prediction</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for i, pred in enumerate(predictions) %}
                                <tr>
                                    <td>{{ i + 1 }}</td>
                                    <td><span class="badge bg-primary">{{ pred }}</span></td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>

                    {% if predictions|length == 100 %}
                    <p class="text-muted small">
                        <i class="fas fa-info-circle"></i> Showing first 100 predictions. 
                        Download the full file to see all results.
                    </p>
                    {% endif %}

                    <div class="d-grid gap-2 mt-3">
                        <a href="{{ url_for('static', filename='predictions.csv') }}" 
                           class="btn btn-success btn-lg" download>
                            <i class="fas fa-download"></i> Download Full Predictions (CSV)
                        </a>
                        <button type="button" class="btn btn-outline-primary" onclick="location.reload()">
                            <i class="fas fa-redo"></i> Make Another Prediction
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% else %}
    <!-- Upload Form for Prediction -->
    <div class="row">
        <div class="col-lg-8 mx-auto">
            <div class="card shadow">
                <div class="card-header bg-primary text-white">
                    <h4 class="mb-0">
                        <i class="fas fa-upload"></i> Upload Data for Prediction
                    </h4>
                </div>
                <div class="card-body">
                    <form action="{{ url_for('predict') }}" method="post" enctype="multipart/form-data">
                        <div class="mb-4">
                            <label for="file" class="form-label">
                                <strong>Select your dataset file</strong>
                            </label>
                            <input type="file" class="form-control" id="file" name="file" 
                                   accept=".csv,.xlsx,.xls,.json" required>
                            <div class="form-text">
                                Upload a file with the same features as your training data
                            </div>
                        </div>

                        <div class="alert alert-info">
                            <h6 class="alert-heading">
                                <i class="fas fa-info-circle"></i> Important Notes:
                            </h6>
                            <ul class="mb-0">
                                <li>Ensure your data has the <strong>same features</strong> as the training data</li>
                                <li>Feature names and order should match</li>
                                <li>Do NOT include the target column in prediction data</li>
                                <li>Missing values will be handled automatically</li>
                            </ul>
                        </div>

                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary btn-lg">
                                <i class="fas fa-play"></i> Generate Predictions
                            </button>
                            <a href="{{ url_for('index') }}" class="btn btn-outline-secondary">
                                <i class="fas fa-arrow-left"></i> Back to Home
                            </a>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
    {% endif %}
</div>

{% if predictions %}
<script>
// Add enumerate filter functionality
Jinja2.filters.enumerate = function(arr) {
    return arr.map((item, index) => [index, item]);
};
</script>
{% endif %}
{% endblock %}