Spaces:
Configuration error

File size: 3,151 Bytes
a4edd2a
 
 
 
 
44560e9
a4edd2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44560e9
a4edd2a
44560e9
a4edd2a
 
44560e9
 
 
 
 
 
 
a4edd2a
 
 
 
44560e9
 
 
 
 
 
 
 
 
 
 
 
 
a4edd2a
 
 
44560e9
 
 
 
 
 
a4edd2a
44560e9
 
a4edd2a
 
 
 
 
 
 
 
44560e9
a4edd2a
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Makale Chatbot</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .container {
            max-width: 600px;
            margin: auto;
        }
        form {
            display: flex;
            flex-direction: column;
        }
        label, input, button {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Bilgileri Doldurunuz!</h1>
        <form id="dataForm">
            <label for="title">Başlık:</label>
            <input type="text" id="title" name="title" required>

            <label for="text">Metin:</label>
            <textarea id="text" name="text" rows="4" required></textarea>

            <label for="keywords">Anahtar Kelimeler:</label>
            <input type="text" id="keywords" name="keywords" required>

            <button type="submit">Sonuç</button>
        </form>
        <p id="responseMessage"></p>
    </div>
    <script>
        // Kullanıcı ID'sini almak için GET isteği
        async function getUserId() {
            const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/user'; // Kullanıcı ID'si almak için API Gateway URL'nizi buraya koyun
            try {
                const response = await fetch(apiUrl);
                const result = await response.json();
                return result.user_id; // API'nin döndürdüğü kullanıcı ID'sini döndürün
            } catch (error) {
                console.error('Error fetching user ID:', error);
                return null;
            }
        }

        document.getElementById('dataForm').addEventListener('submit', async (e) => {
            e.preventDefault();
            
            const userId = await getUserId();
            if (!userId) {
                document.getElementById('responseMessage').textContent = 'Unable to get user ID.';
                return;
            }

            const title = document.getElementById('title').value;
            const text = document.getElementById('text').value;
            const keywords = document.getElementById('keywords').value;
            const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/users'; // API Gateway URL'nizi buraya koyun

            try {
                const response = await fetch(apiUrl, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ user_id: userId, title: title, text: text, keywords: keywords })
                });

                const result = await response.json();
                document.getElementById('responseMessage').textContent = `Response: ${JSON.stringify(result)}`;
            } catch (error) {
                document.getElementById('responseMessage').textContent = `Error: ${error}`;
            }
        });
    </script>
</body>
</html>