File size: 3,217 Bytes
23004ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Write | TaskBot v1+ AI</title>
    <link rel="Icon" href="TaskBot logo.png">
    </link>
</head>
<style>

    body {

        background-color: #2f2f2f;

        font-family: Arial, sans-serif;

        color: white;

        margin: 0;

        padding: 20px;

    }



    h1 {

        text-align: center;

    }



    #topic {

        width: 100%;

        border-radius: 50px;

        background-color: white;

        color: black;

        height: 40px;

        font-size: large;

    }



    select {

        border-radius: 50px;

    }



    input {

        border-radius: 50px;

    }



    textarea {

        height: 300px;

        width: 100%;

    }



    button {

        width: 100px;

        height: 50px;

        text-align: center;

        float: right;

    }



    small {

        color: gray;

        display: block;

        text-align: center;

    }

</style>

<body>
    <h1>Write Mate</h1>
    <small>Powered by gemini-2.0-flash</small>

    <lable for="topic">Topic:</lable>
    <input type="text" id="topic"><br><br><br>

    <label for="fruits">Type: </label>
    <select id="type" name="type">
        <option value="para">Paragraph</option>
        <option value="essay">Essay</option>
        <option value="speech">Speech</option>
    </select><br><br><br>

    <label for="word-limit">Word Limit: </label>
    <input type="number" id="word-limit"><br><br><br>

    <button onclick=answer() id="answer_button">Start Writing</button><br><br>

    <textarea name="answer" id="answer" placeholder="Your answer will be displayed here..."></textarea>

    <script>

        async function answer() {

            document.getElementById("answer_button").disabled = true

            const userInput = document.getElementById('topic').value;

            if (userInput.trim() === '') return;



            const word_limit = document.getElementById("word-limit").value;

            const type = document.getElementById("type").value;



            try {

                const response = await fetch("/write", {

                    method: "POST",

                    headers: { "Content-Type": "application/x-www-form-urlencoded" },

                    body: new URLSearchParams({ question: userInput, word_limit: word_limit, type: type })

                });



                const data = await response.json();

                console.log("Server Response:", data); // DEBUG LINE



                const answer_area = document.getElementById("answer");

                if (data.answer) {

                    answer_area.value = data.answer; // set textarea value

                } else if (data.error) {

                    answer_area.value = "Error: " + data.error;

                }

            } catch (err) {

                console.error("Fetch Error:", err);

                document.getElementById("answer").value = err;

            }

            document.getElementById("answer_button").disabled = false

        }



    </script>
</body>

</html>