Update frontend/src/App.jsx
Browse files- frontend/src/App.jsx +61 -95
frontend/src/App.jsx
CHANGED
|
@@ -1,111 +1,77 @@
|
|
| 1 |
-
import
|
| 2 |
-
import Plot from 'react-plotly.js';
|
| 3 |
|
| 4 |
function App() {
|
| 5 |
-
const [
|
| 6 |
-
const [
|
| 7 |
-
const [
|
| 8 |
-
const [loading, setLoading] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
const runSimulation = async () => {
|
| 11 |
-
setLoading(true);
|
| 12 |
try {
|
| 13 |
-
|
|
|
|
| 14 |
method: 'POST',
|
| 15 |
headers: { 'Content-Type': 'application/json' },
|
| 16 |
-
body: JSON.stringify({
|
| 17 |
-
})
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
-
setLoading(false)
|
| 24 |
-
}
|
| 25 |
|
| 26 |
return (
|
| 27 |
-
<div className="min-h-screen bg-gray-900 text-white p-8">
|
| 28 |
-
<
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
<
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
value={message}
|
| 40 |
-
onChange={e => setMessage(e.target.value)}
|
| 41 |
-
className="w-full p-3 text-black rounded mb-6 font-mono"
|
| 42 |
-
/>
|
| 43 |
-
|
| 44 |
-
<label className="block mb-2 font-mono text-sm text-yellow-400">
|
| 45 |
-
Channel Condition (SNR): {snr} dB
|
| 46 |
-
</label>
|
| 47 |
-
<input
|
| 48 |
-
type="range" min="-5" max="30" step="1"
|
| 49 |
-
value={snr} onChange={e => setSnr(e.target.value)}
|
| 50 |
-
className="w-full mb-8 cursor-pointer"
|
| 51 |
/>
|
| 52 |
-
|
| 53 |
-
<button
|
| 54 |
-
onClick={runSimulation}
|
| 55 |
-
className="bg-blue-600 hover:bg-blue-500 transition-colors px-6 py-3 rounded font-bold w-full text-lg tracking-wide"
|
| 56 |
-
disabled={loading}
|
| 57 |
-
>
|
| 58 |
-
{loading ? "Simulating Physical Channel..." : "Transmit Signal"}
|
| 59 |
-
</button>
|
| 60 |
-
|
| 61 |
-
{results && (
|
| 62 |
-
<div className="mt-8 space-y-4">
|
| 63 |
-
<div className="p-4 bg-red-900/30 border-l-4 border-red-500 rounded">
|
| 64 |
-
<h3 className="font-bold text-red-400 text-sm tracking-wider uppercase mb-1">Traditional PHY Decoder</h3>
|
| 65 |
-
<p className="font-mono text-gray-300">{results.corrupted_message}</p>
|
| 66 |
-
</div>
|
| 67 |
-
<div className="p-4 bg-green-900/30 border-l-4 border-green-500 rounded">
|
| 68 |
-
<h3 className="font-bold text-green-400 text-sm tracking-wider uppercase mb-1">AI Semantic Recovery</h3>
|
| 69 |
-
<p className="font-mono text-white">{results.recovered_message}</p>
|
| 70 |
-
</div>
|
| 71 |
-
</div>
|
| 72 |
-
)}
|
| 73 |
</div>
|
| 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 |
-
yaxis: { range: [-5, 5], gridcolor: '#374151', zerolinecolor: '#4B5563' },
|
| 99 |
-
showlegend: true, legend: { orientation: 'h', y: -0.2 }
|
| 100 |
-
}}
|
| 101 |
-
/>
|
| 102 |
-
) : (
|
| 103 |
-
<div className="text-gray-500 font-mono animate-pulse">Awaiting Signal Transmission...</div>
|
| 104 |
-
)}
|
| 105 |
-
</div>
|
| 106 |
</div>
|
| 107 |
</div>
|
| 108 |
-
)
|
| 109 |
}
|
| 110 |
|
| 111 |
-
export default App
|
|
|
|
| 1 |
+
import { useState } from 'react'
|
|
|
|
| 2 |
|
| 3 |
function App() {
|
| 4 |
+
const [inputText, setInputText]] = useState("Critical satellite telemetry data sequence initialized.")
|
| 5 |
+
const [corruptedText, setCorruptedText] = useState("")
|
| 6 |
+
const [decodedText, setDecodedText] = useState("")
|
| 7 |
+
const [loading, setLoading] = useState(false)
|
| 8 |
+
|
| 9 |
+
const handleTransmit = async () => {
|
| 10 |
+
setLoading(true)
|
| 11 |
+
setCorruptedText("")
|
| 12 |
+
setDecodedText("")
|
| 13 |
|
|
|
|
|
|
|
| 14 |
try {
|
| 15 |
+
// 1. Send your custom text to the backend
|
| 16 |
+
const response = await fetch('/api/transmit', {
|
| 17 |
method: 'POST',
|
| 18 |
headers: { 'Content-Type': 'application/json' },
|
| 19 |
+
body: JSON.stringify({ text: inputText })
|
| 20 |
+
})
|
| 21 |
+
|
| 22 |
+
const data = await response.json()
|
| 23 |
+
|
| 24 |
+
// 2. Display the results
|
| 25 |
+
setCorruptedText(data.corrupted)
|
| 26 |
+
setDecodedText(data.decoded)
|
| 27 |
+
} catch (error) {
|
| 28 |
+
setDecodedText("Error connecting to the server.")
|
| 29 |
}
|
| 30 |
+
setLoading(false)
|
| 31 |
+
}
|
| 32 |
|
| 33 |
return (
|
| 34 |
+
<div className="min-h-screen bg-gray-900 text-white p-8 font-sans">
|
| 35 |
+
<div className="max-w-2xl mx-auto space-y-6">
|
| 36 |
+
<h1 className="text-3xl font-bold text-blue-400">🧠 6G Semantic Decoder</h1>
|
| 37 |
+
|
| 38 |
+
{/* The New Text Input Box */}
|
| 39 |
+
<div className="space-y-2">
|
| 40 |
+
<label className="text-sm text-gray-400">Message to Transmit:</label>
|
| 41 |
+
<textarea
|
| 42 |
+
className="w-full p-3 bg-gray-800 rounded border border-gray-700 text-white"
|
| 43 |
+
rows="3"
|
| 44 |
+
value={inputText}
|
| 45 |
+
onChange={(e) => setInputText(e.target.value)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</div>
|
| 48 |
|
| 49 |
+
<button
|
| 50 |
+
onClick={handleTransmit}
|
| 51 |
+
disabled={loading}
|
| 52 |
+
className="w-full bg-blue-600 hover:bg-blue-500 text-white font-bold py-3 px-4 rounded transition-colors"
|
| 53 |
+
>
|
| 54 |
+
{loading ? "Transmitting..." : "Transmit Message"}
|
| 55 |
+
</button>
|
| 56 |
+
|
| 57 |
+
{/* Display the Corrupted Text */}
|
| 58 |
+
{corruptedText && (
|
| 59 |
+
<div className="p-4 bg-red-900/30 border border-red-700 rounded">
|
| 60 |
+
<h3 className="text-red-400 text-sm font-bold mb-1">Traditional PHY Decoder (Noisy):</h3>
|
| 61 |
+
<p className="font-mono">{corruptedText}</p>
|
| 62 |
+
</div>
|
| 63 |
+
)}
|
| 64 |
+
|
| 65 |
+
{/* Display the AI Decoded Text */}
|
| 66 |
+
{decodedText && (
|
| 67 |
+
<div className="p-4 bg-green-900/30 border border-green-700 rounded">
|
| 68 |
+
<h3 className="text-green-400 text-sm font-bold mb-1">AI Semantic Recovery:</h3>
|
| 69 |
+
<p className="font-mono">{decodedText}</p>
|
| 70 |
+
</div>
|
| 71 |
+
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
</div>
|
| 73 |
</div>
|
| 74 |
+
)
|
| 75 |
}
|
| 76 |
|
| 77 |
+
export default App
|