The Language Prediction Web App is a tool for predicting the language of a given text. Built using FastAPI for the backend and HTML, CSS, and JavaScript for the frontend, this application provides a user-friendly interface for language detection. It handles various inputs and displays appropriate messages for both prediction and errors.
- Language Prediction: Predict the language of a given text using an ML model.
- Responsive Design: Optimized for both desktop and mobile devices.
- Error Handling: Displays a user-friendly message when no text is entered.
- Loading Indicator: Shows a loading message while processing the prediction.
The project is organized as follows:
Language-predictor/
├── app
│ ├── main.py
│ ├── model
│ │ ├── model.py
│ │ └── trained_pipeline-0.1.0.pkl
│ ├── requirements.txt
│ ├── static
│ │ ├── css
│ │ │ └── styles.css
│ │ └── js
│ │ └── script.js
│ └── templates
│ └── index.html
└── README.md
Ensure you have the following installed:
- Python 3.7+: Required for running the FastAPI application.
- pip: Python package installer.
-
Clone the Repository
git clone https://github.com/ganeshborkar31/Language-predictor.git cd Language-predictor
-
Create and Activate a Virtual Environment
python -m venv myvenv source myvenv/bin/activate # On Windows, use `myvenv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Ensure requirements.txt includes:
fastapi uvicorn pydantic scikit-learn
-
Run the FastAPI application:
cd app python -m uvicorn app.main:app --reload
The application will be available at http://127.0.0.1:8000.
- Open your browser and navigate to http://127.0.0.1:8000.
- Enter the text you want to analyze in the text box.
- Click the "Predict" button.
- The predicted language or an error message will be displayed below the button.
-
Request Body:
{ "text": "input text" }
-
Response:
-
On success:
{ "language": "Predicted Language" }
-
On error (empty input):
{ "error": "Please enter some text." }
-
-
- Solution: Ensure the input is a string and properly extracted in the FastAPI endpoint.
-
Using nohup
-
The nohup (no hang-up) command allows processes to continue running in the background even after you log out from the SSH session.
-
Run the Command with nohup:
nohup python -m uvicorn main:app --host 0.0.0.0 --port 8000 > server.log 2>&1 &
-
-
nohup: Prevents the process from being stopped when you log out.
server.log 2>&1: Redirects both stdout and stderr to server.log. &: Runs the command in the background.
-
Verify the Process:
- You can check if the server is running by looking for the process:
ps aux | grep uvicorn
-
-
Stop the Process (if needed):
- To stop the process, you’ll need to find its process ID (PID) and then kill it:
kill <PID>
-
- Overview: Brief introduction to what the project does.
- Project Structure: Overview of the project directory and files.
- Getting Started: Instructions to set up and run the project locally.
- Usage: How to use the web application.
- API Endpoints: Details of the API endpoint used by the frontend.
- Troubleshooting: Common issues and their solutions.
- Contact: Contact information for feedback or questions.
Feel free to adjust the content according to your project's specific details and requirements!