File size: 1,169 Bytes
63146b6
 
 
00b6148
 
 
3ddd811
d4f7f08
63146b6
 
 
00b6148
 
 
63146b6
00b6148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63146b6
00b6148
63146b6
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
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
import os

# Import your simulation and AI scripts
from backend.comm_system import simulate_channel
from backend.ai_decoder import decode_semantic_intent

app = FastAPI()

# This tells Python exactly what the React app is sending
class MessageRequest(BaseModel):
    text: str

# 📡 The endpoint that listens for the "Transmit Message" button
@app.post("/api/transmit")
async def transmit_message(req: MessageRequest):
    try:
        # 1. Pass the user's text through the noisy channel
        corrupted_text = simulate_channel(req.text)
        
        # 2. Ask the Hugging Face AI to fix it
        decoded_text = decode_semantic_intent(corrupted_text)
        
        # 3. Send both back to the React UI
        return {
            "corrupted": corrupted_text,
            "decoded": decoded_text
        }
    except Exception as e:
        return {"corrupted": "Error in channel", "decoded": f"Backend Error: {str(e)}"}

# Mount the React frontend so the browser can see it
app.mount("/", StaticFiles(directory="frontend/dist", html=True), name="static")