How mminh007/machine-translation works
Project type and purpose
• This is a full-stack, real-time translation application.
• Frontend: Streamlit UI (Python) for capturing text/audio and displaying results.
• Backend: FastAPI service that exposes translation endpoints.
• Core functionality: on-the-fly translation (Vietnamese ↔ English) using Facebook’s MBart model, plus audio capture/recognition (Google SpeechRecognition API).
• Exposed publicly via ngrok tunnels for both API and UI.
File structure
• app.py (root)
– Orchestrates startup: launches backend (FastAPI), frontend (Streamlit), and ngrok tunnels.
• backend/
– main.py: FastAPI app, endpoint definitions (text and audio translation).
– schema/base.py: Pydantic models for request/response payloads.
– utils/model.py: loads the MBart model, performs inference.
• frontend/
– main.py: Streamlit script—defines UI controls (text inputs, microphone capture), calls backend endpoints.
• requirements.txt: lists dependencies (FastAPI, Streamlit, transformers, pyngrok, SpeechRecognition, etc.)
README for additional insights
• Two servers run concurrently: FastAPI (port 8000) and Streamlit (port 8501).
• Ngrok configured via a .env token—creates public URLs for both.
• Features: text translation API, audio recording in browser → backend OCR/recognition → translation.
Detail
• Startup orchestration: app.py → spawns both services and ngrok tunnels.
• Environment variables (.env → NGROK_TOKEN) feeding into PyNgrok initialization.
• Call out key ports: 8501 (frontend), 8000 (backend).