File size: 1,269 Bytes
4916b2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script>
    function generateStory() {
        // Get the selected options
        var genre = document.querySelector('input[name="genre"]:checked').value;
        var storyTeller = document.querySelector('input[name="story_teller"]:checked').value;
        var storyTellingStyle = document.querySelector('input[name="story_telling_style"]:checked').value;
        var creativity = document.querySelector('input[name="creativity"]:checked').value;
        
        // Call the Flask endpoint to generate the story
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "/generate_story", true);
        xhr.setRequestHeader("Content-Type", "application/json");
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                // Update the HTML with the generated story
                document.querySelector("#generated-story").innerHTML = xhr.responseText;
            }
        };
        xhr.send(JSON.stringify({
            "genre": genre,
            "story_teller": storyTeller,
            "story_telling_style": storyTellingStyle,
            "creativity": creativity
        }));
    }
</script>

<button onclick="generateStory()">Generate Story</button>
<div id="generated-story"></div>