File size: 3,443 Bytes
9860c76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Property Recommendation</title>
    <style>

        body { font-family: Arial, sans-serif; background: #f4f4f4; margin: 0; padding: 0; }

        .container { max-width: 400px; margin: 60px auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

        h2 { text-align: center; }

        label { display: block; margin-top: 15px; }

        input, select { width: 100%; padding: 8px; margin-top: 5px; border-radius: 4px; border: 1px solid #ccc; }

        button { width: 100%; padding: 10px; margin-top: 20px; background: #007bff; color: #fff; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; }

        button:hover { background: #0056b3; }

        .recommendations { margin-top: 30px; }

        .property { background: #f9f9f9; padding: 15px; border-radius: 6px; margin-bottom: 15px; }

    </style>
</head>
<body>
    <div class="container">
        <h2>Find Your Property</h2>
        <form id="propertyForm">
            <label for="propertyType">Property Type</label>
            <select id="propertyType" required>
                <option value="">Select type</option>
                <option value="Villa">Villa</option>
                <option value="Townhouse">Townhouse</option>
                <option value="Apartment">Apartment</option>
                <option value="Flat">Flat</option>
                <option value="Office Space">Office Space</option>
            </select>
            <label for="price">Price</label>
            <input type="number" id="price" required placeholder="Enter price">
            <button type="submit">Next</button>
        </form>
        <div class="recommendations" id="recommendations"></div>
    </div>
    <script>

        document.getElementById('propertyForm').addEventListener('submit', async function(e) {

            e.preventDefault();

            const propertyType = document.getElementById('propertyType').value;

            const price = document.getElementById('price').value;

            const resDiv = document.getElementById('recommendations');

            resDiv.innerHTML = '<p>Loading recommendations...</p>';

            try {

                const response = await fetch('/recommend', {

                    method: 'POST',

                    headers: { 'Content-Type': 'application/json' },

                    body: JSON.stringify({ propertyType, price })

                });

                const data = await response.json();

                if (data.recommendations && data.recommendations.length > 0) {

                    resDiv.innerHTML = data.recommendations.map(p => `

                        <div class="property">

                            <strong>Type:</strong> ${p.propertyType}<br>

                            <strong>Price:</strong> ${p.price}<br>

                            <strong>Description:</strong> ${p.description}<br>

                        </div>

                    `).join('');

                } else {

                    resDiv.innerHTML = '<p>No recommendations found.</p>';

                }

            } catch (err) {

                resDiv.innerHTML = '<p>Error fetching recommendations.</p>';

            }

        });

    </script>
</body>
</html>