Spaces:
Configuration error
Configuration error
File size: 1,642 Bytes
dad4133 1438e56 dad4133 1438e56 dad4133 1438e56 dad4133 1438e56 dad4133 1438e56 dad4133 |
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 |
import React, { useState } from "react";
function StoryGenerator() {
const [userInput, setUserInput] = useState("");
const [result, setResult] = useState(null);
const [loading, setLoading] = useState(false);
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
setResult(null);
try {
const response = await fetch("http://localhost:8000/generate-story", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_input: userInput }),
});
const data = await response.json();
setResult(data);
} catch (err) {
setResult({ error: "Failed to connect to backend." });
}
setLoading(false);
};
return (
<div>
<form onSubmit={handleSubmit}>
<textarea
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
placeholder="Enter your story idea..."
/>
<button type="submit" disabled={loading}>
{loading ? "Generating..." : "Generate Story"}
</button>
</form>
{result && (
<div>
{result.error ? (
<div style={{ color: "red" }}>{result.error}</div>
) : (
<div>
<h3>Genre: {result.genre}</h3>
<h4>Tone: {result.tone}</h4>
<p><strong>Outline:</strong> {result.outline}</p>
<p><strong>Scene:</strong> {result.scene}</p>
<pre><strong>Dialogue:</strong> {result.dialogue}</pre>
</div>
)}
</div>
)}
</div>
);
}
export default StoryGenerator; |