'use client'
import { useState } from 'react'
import { usePython } from 'react-py'
const packages = {
official: ['pandas'],
micropip: ['pandas'],
}
export default function Home() {
const [input, setInput] = useState('')
// Use the usePython hook to run code and access both stdout and stderr
const { runPython, stdout, stderr, isLoading, isRunning } = usePython(packages)
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<>
{isLoading ? <p>Loading...</p> : <p>Ready!</p>}
<form>
<textarea
onChange={(e) => setInput(e.target.value)}
placeholder="Enter your code here"
/>
<input
type="submit"
value={!isRunning ? 'Run' : 'Running...'}
disabled={isLoading || isRunning}
onClick={(e) => {
e.preventDefault()
runPython(input)
}}
/>
</form>
<p>Output</p>
<pre>
<code>{stdout}</code>
</pre>
<p>Error</p>
<pre>
<code>{stderr}</code>
</pre>
</>
</main>
);
}