File size: 4,374 Bytes
ae52d5c
04aab93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae52d5c
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>COVID-19 Data Prediction</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css" />
</head>
<body>
    <div class="container mt-5">
        <h1 class="mb-4">COVID-19 Data Prediction</h1>
        <p>Enter the text to predict:</p>
        <input type="text" id="textInput" class="form-control mb-3" placeholder="Text to predict">
        <button id="predictBtn" class="btn btn-primary">Predict</button>
    </div>
    <div class="container mt-4" id="resultContainer" style="display: none;">
        <h2>Prediction Result</h2>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>Key</th>
                    <th>Value</th>
                </tr>
            </thead>
            <tbody id="predictionTableBody">
            </tbody>
        </table>
        <button id="showMapBtn" class="btn btn-primary">Show Map</button>
        <div id="map" class="mt-3" style="width: 100%; height: 400px;"></div>
    </div>
    
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js"></script>
    <script>
        $(document).ready(function() {
            var map = null;
            var predictionResult = null;

            $("#predictBtn").click(function() {
                var inputText = $("#textInput").val();
                var apiUrl = "https://docfile-covid-19.hf.space/run/predict";
                var requestBody = {
                    data: [inputText]
                };
                
                $.ajax({
                    type: "POST",
                    url: apiUrl,
                    headers: { "Content-Type": "application/json" },
                    data: JSON.stringify(requestBody),
                    success: function(response) {
                        predictionResult = response.data[0];
                        var translationMap = {
                            "country": "Pays",
                            "confirmed": "Confirmé",
                            "active": "Actif",
                            "deaths": "Décès",
                            "recovered": "Guéris",
                            "latitude": "Latitude",
                            "longitude": "Longitude"
                            // Ajoutez d'autres traductions si nécessaire
                        };
                        
                        var predictionTable = "";
                        
                        for (var key in predictionResult) {
                            var translatedKey = translationMap[key] || key;
                            var value = predictionResult[key] === null ? "Aucun" : predictionResult[key];
                            predictionTable += "<tr><td>" + translatedKey + "</td><td>" + value + "</td></tr>";
                        }
                        
                        $("#predictionTableBody").html(predictionTable);
                        $("#resultContainer").show();
                    },
                    error: function(error) {
                        console.error("Prediction error:", error);
                    }
                });
            });

            $("#showMapBtn").click(function() {
                if (map === null && predictionResult !== null) {
                    var latitude = parseFloat(predictionResult.latitude);
                    var longitude = parseFloat(predictionResult.longitude);

                    map = L.map('map').setView([latitude, longitude], 10);

                    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
                    }).addTo(map);

                    L.marker([latitude, longitude]).addTo(map)
                        .bindPopup('Latitude: ' + latitude + '<br>Longitude: ' + longitude)
                        .openPopup();
                }
            });
        });
    </script>
</body>
</html>