A Flask-based frontend server that connects to a fine-tuned Mistral Legal Advisor model running on Google Colab. The model runs on Colab's GPU and generates comprehensive legal document lists for startups, while your local Flask server provides a beautiful web interface.
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Web Browser β βββββββΊ β Flask Server β βββββββΊ β Colab Model β
β (Your Local) β β (Your Local) β β (Cloud GPU) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
index.html app.py proxies Mistral Model
app.js requests to Colab on GPU
style.css
Legal-Advisor/
βββ app.py # Flask server (proxies to Colab)
βββ colab_mistral_model_server.ipynb # Run this on Google Colab
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ Screenshots/ # Application screenshots
βββ static/
βββ index.html # Frontend UI
βββ app.js # Frontend logic
βββ style.css # Styling
-
Open the Colab Notebook
- Upload or open
colab_mistral_model_server.ipynbin Google Colab
- Upload or open
-
Get Your Tokens
- Hugging Face Token: Visit https://huggingface.co/settings/tokens and create a new token
- ngrok Token: Visit https://dashboard.ngrok.com/get-started/your-authtoken and copy your authtoken
-
Add Tokens in Colab
- In the Colab notebook, locate the cell where tokens are required
- Add your Hugging Face token when prompted or in the designated cell
- Add your ngrok authtoken in the ngrok configuration cell
- These tokens are needed for authentication and creating the public tunnel
-
Run All Cells in the Notebook
- Install dependencies
- Login to Hugging Face
- Configure ngrok
- Load the Mistral model (this may take a few minutes)
- Start the Flask API server
-
Copy the ngrok URL
- After running all cells, you'll see an ngrok URL (looks like:
https://xxxx-xx-xx-xx-xx.ngrok-free.app) - Copy this URL - you'll need it for the frontend
- After running all cells, you'll see an ngrok URL (looks like:
-
Install Python Dependencies
pip install -r requirements.txt
-
Run the Flask Server
python app.py
-
Open Your Browser
- Navigate to:
http://localhost:7860
- Navigate to:
-
Configure the Frontend
- In the web interface, click on the settings icon
- Paste the ngrok URL from Step 1 into the "Colab API URL" field
- Start generating text!
This is the home page and main landing page of the application.
Paste the ngrok URL from the Colab notebook here to connect the frontend to the model server.
Question interface for multiple-choice options.
Interface for multi-select options.
Frontend display shown while the model is generating the response.
Example of the model generating a comprehensive legal document list based on the questionnaire responses. This includes an option to export the result as a PDF.
- User enters a prompt in the web interface
- Frontend (app.js) sends a POST request to local Flask server with the Colab API URL
- Flask server (app.py) proxies the request to Colab via ngrok URL
- Colab processes the prompt using the Mistral model on GPU
- Response flows back: Colab β Flask β Browser
- Generated text is displayed in the UI
Local Flask Server (http://localhost:7860)
Serves the frontend web interface
Check if the server is running
Response:
{
"status": "ok",
"message": "Frontend server is running"
}Generate text using the model (proxies to Colab)
Request:
{
"prompt": "Generate legal documents for a tech startup...",
"max_new_tokens": 2048,
"temperature": 0.5,
"top_p": 0.9,
"colab_api_url": "https://xxxx-xx-xx-xx-xx.ngrok-free.app"
}Response:
{
"generated_text": "{\"required_documents\": [...], \"descriptions\": [...]}"
}The Colab notebook runs a Flask server that exposes:
Direct model inference endpoint
Adjust these in the web interface:
- Max Tokens: 512-2048 (length of generated document list, default: 2048)
- Temperature: 0.1-1.0 (response consistency, default: 0.5)
- Top P: 0.1-1.0 (nucleus sampling, default: 0.9)
- β Check if Colab notebook is running
- β Verify ngrok URL is correct in the frontend settings
- β Make sure ngrok cell in Colab has run successfully
- β Enter the ngrok URL in the frontend settings (gear icon)
- β Make sure you copied the complete URL from Colab
- β Model is loading (first request takes longer)
- β Colab GPU might be slow
- β
Increase timeout in
app.pyif needed
- β Check if Flask server is running
- β
Visit
http://localhost:7860(not file://) - β Check browser console for errors
- Colab session expires after inactivity (~6 hours on free tier)
- ngrok URL changes each time you restart the Colab notebook
- Update the frontend settings with the new ngrok URL after restarting
- Free Colab has usage limits - consider Colab Pro for heavy use
- Model:
KASHH-4/Mistral-Model-Legal-Advisorloaded with 4-bit quantization - Purpose: Generates comprehensive JSON lists of required legal documents for startups
- β¨ Modern, responsive UI
- π Multi-step questionnaire for startup information
- βοΈ Configurable Colab API URL via settings
- π― Real-time generation status updates
- π Loading indicators during model inference
- β Error handling with clear messages
- π Export generated legal document lists as PDF
- Keep your Hugging Face token private - never share it publicly
- Keep your ngrok token private - never commit it to git
- ngrok URLs are public but temporary - they expire when the Colab session ends
- The API URL is configured in the frontend, not in environment files
- Flask: Web server framework
- Flask-CORS: Cross-origin resource sharing
- requests: HTTP library for API calls
All dependencies are listed in requirements.txt
Model by: KASHH-4
Model: Mistral-Model-Legal-Advisor
Purpose: Legal Document Generator for Startups
Platform: Google Colab + Local Flask





