MalikShehram commited on
Commit
8f672ce
·
verified ·
1 Parent(s): 9daebc2

Update frontend/src/App.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/App.jsx +61 -95
frontend/src/App.jsx CHANGED
@@ -1,111 +1,77 @@
1
- import React, { useState } from 'react';
2
- import Plot from 'react-plotly.js';
3
 
4
  function App() {
5
- const [snr, setSnr] = useState(20);
6
- const [message, setMessage] = useState("Critical satellite telemetry data sequence initialized.");
7
- const [results, setResults] = useState(null);
8
- const [loading, setLoading] = useState(false);
 
 
 
 
 
9
 
10
- const runSimulation = async () => {
11
- setLoading(true);
12
  try {
13
- const response = await fetch('/api/simulate', {
 
14
  method: 'POST',
15
  headers: { 'Content-Type': 'application/json' },
16
- body: JSON.stringify({ snr_db: parseFloat(snr), message })
17
- });
18
- const data = await response.json();
19
- setResults(data);
20
- } catch (err) {
21
- console.error(err);
 
 
 
 
22
  }
23
- setLoading(false);
24
- };
25
 
26
  return (
27
- <div className="min-h-screen bg-gray-900 text-white p-8">
28
- <h1 className="text-4xl font-bold mb-8 border-b border-gray-700 pb-4">
29
- Neural-Link: Generative Signal Recovery
30
- </h1>
31
-
32
- <div className="grid grid-cols-2 gap-8">
33
- <div className="bg-gray-800 p-6 rounded-lg shadow-xl border border-gray-700">
34
- <h2 className="text-2xl mb-4 font-semibold text-blue-400">Transmission Parameters</h2>
35
-
36
- <label className="block mb-2 font-mono text-sm">Target Semantic Intent:</label>
37
- <input
38
- type="text"
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
- <div className="bg-gray-800 p-6 rounded-lg shadow-xl border border-gray-700 flex justify-center items-center">
76
- {results ? (
77
- <Plot
78
- data={[
79
- {
80
- x: results.constellation.ideal_i,
81
- y: results.constellation.ideal_q,
82
- mode: 'markers', type: 'scatter', name: 'Ideal Map',
83
- marker: { color: '#60A5FA', size: 8, symbol: 'cross' }
84
- },
85
- {
86
- x: results.constellation.noisy_i,
87
- y: results.constellation.noisy_q,
88
- mode: 'markers', type: 'scatter', name: 'Received Noise',
89
- marker: { color: 'rgba(239, 68, 68, 0.6)', size: 5 }
90
- }
91
- ]}
92
- layout={{
93
- width: 500, height: 500,
94
- title: 'Real-Time 16-QAM Constellation',
95
- paper_bgcolor: 'transparent', plot_bgcolor: 'transparent',
96
- font: { color: 'white', family: 'monospace' },
97
- xaxis: { range: [-5, 5], gridcolor: '#374151', zerolinecolor: '#4B5563' },
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