Skip to main content
The Flask starter template is a lightweight Python application with a Preact frontend. Perfect for developers who prefer Python and want a simple, no-build-tools approach.

Quick Start

1

Clone the template

2

Create virtual environment

3

Install dependencies

4

Configure environment

Create a .env file:
.env
Get your API key from the Developer Portal.
5

Update scenario ID

Edit www/config.js:
www/config.js
6

Run the app

Visit http://localhost:8008

What’s Included

Flask Backend

Secure API proxy routes to protect your API key

Preact Frontend

Lightweight React alternative, no build tools needed

Iframe Integration

Ready-to-use ToughTongue embed with event handling

Session Analysis

Built-in analysis endpoint integration

Project Structure


Core Integration Patterns

1. Embedding the Iframe

The iframe is embedded in www/assessment.js:

2. Listening for Events

Handle iframe events in www/assessment.js:

3. Analyzing Sessions

After a session completes, analyze it via the backend API: Frontend (www/assessment.js):
Backend (api/index.py):

API Endpoints

The Flask backend provides these API proxy routes:

POST /api/analyze

Analyzes a completed session:

GET /api/sessions/<session_id>

Retrieves session details:

Customization

Changing the Scenario

Update the scenario ID in www/config.js:

Styling

Modify www/styles.css to customize appearance. The starter includes:
  • Responsive layout
  • Card-based UI components
  • Smooth transitions
  • CSS variables for theming

Adding New API Endpoints

Add routes in api/index.py:

Adding New Components

Create files in www/components/:

Environment Variables


Deployment

The project includes vercel.json for serverless deployment:
1

Install Vercel CLI

2

Deploy

3

Add environment variables

In Vercel dashboard, add TTAI_TOKEN to your project’s environment variables.
4

Deploy to production

Other Platforms

For other platforms (Heroku, Railway, etc.):
  1. Ensure Python 3.9+ is available
  2. Set environment variables
  3. Configure start command: python app.py
  4. Ensure port is configurable via PORT environment variable
For production, consider using gunicorn:

Troubleshooting

Check:
  • Verify TTAI_TOKEN is set correctly in .env
  • Check token hasn’t expired
  • Ensure token has necessary permissions
Check: - Verify scenario ID is correct in www/config.js - Check scenario is set to is_public: true in ToughTongue AI dashboard - Review browser console for errors - Ensure HTTPS is used in production (required for microphone access)
Check: - Check WWW_DIR path in app.py is correct - Verify files exist in www/ directory
  • Check file permissions
Flask-CORS is already configured in api/index.py. If issues persist, check API base URL is correct.

Dependencies

  • Flask 2.0+: Web framework
  • requests: HTTP library for API calls
  • flask-cors: CORS support
  • python-dotenv: Environment variable management
  • gunicorn: Production WSGI server (optional)

Learn More

API Reference

ToughTongue AI API documentation

Iframe Events

Complete iframe integration guide

Troubleshooting

Common issues and solutions