Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/

# Virtual environments
venv/
env/
ENV/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Logs
*.log
logs/

# Model checkpoints and data (large files)
*.ckpt
*.pth
*.pt
245 changes: 245 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
# Deployment Guide - Text2Trait Frontend

This guide explains how to deploy the Text2Trait frontend application using Gunicorn and the provided WSGI entry point.

## Prerequisites

1. Python 3.12 or higher
2. Install dependencies from `text2trait_forntend_app/src/pyproject.toml`:
(Note: The directory name contains a typo 'forntend' - this is the actual name in the repository)
```bash
cd text2trait_forntend_app/src
pip install -r pyproject.toml
# or with poetry:
poetry install
```

3. Install Gunicorn:
```bash
pip install gunicorn
```

## WSGI Entry Point

The `wsgi_t2tfe.py` file at the root of the repository provides a Gunicorn-compatible WSGI entry point for the Text2Trait frontend Dash application.

## Usage

### Local Development

For local development and testing:

```bash
python wsgi_t2tfe.py
```

The application will be available at `http://localhost:8051/`

### Production Deployment with Gunicorn

For production deployment, use Gunicorn:

```bash
gunicorn wsgi_t2tfe:server --bind 0.0.0.0:8051 --workers 4
```

#### Recommended Gunicorn Configuration

```bash
gunicorn wsgi_t2tfe:server \
--bind 127.0.0.1:8051 \
--workers 4 \
--timeout 120 \
--access-logfile /var/log/text2trait/access.log \
--error-logfile /var/log/text2trait/error.log \
--log-level info
```

#### Configuration Options Explained

- `--bind 127.0.0.1:8051` - Bind only to localhost on port 8051
- `--workers 4` - Use 4 worker processes (adjust based on CPU cores: 2-4 × CPU cores)
- `--timeout 120` - Worker timeout in seconds (adjust based on your needs)
- `--access-logfile` - Path for access logs
- `--error-logfile` - Path for error logs
- `--log-level` - Logging level (debug, info, warning, error, critical)

### Running as a Systemd Service

Create a systemd service file `/etc/systemd/system/text2trait-frontend.service`:

```ini
[Unit]
Description=Text2Trait Frontend Application
After=network.target

[Service]
Type=simple
User=harvest
Group=harvest
WorkingDirectory=/path/to/Text2Trait
Environment="PATH=/path/to/venv/bin"
ExecStart=/path/to/venv/bin/gunicorn wsgi_t2tfe:server \
--bind 127.0.0.1:8051 \
--workers 4 \
--timeout 120 \
--access-logfile /var/log/text2trait/access.log \
--error-logfile /var/log/text2trait/error.log
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true

[Install]
WantedBy=multi-user.target
```

Enable and start the service:

```bash
sudo systemctl daemon-reload
sudo systemctl enable text2trait-frontend
sudo systemctl start text2trait-frontend
sudo systemctl status text2trait-frontend
```

### Using with Nginx (Reverse Proxy)

Create an Nginx configuration `/etc/nginx/sites-available/text2trait`:

```nginx
server {
listen 80;
server_name your-domain.com;

location / {
proxy_pass http://127.0.0.1:8051;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# WebSocket support (if needed by Dash)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

# Increase timeouts for long-running requests
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 120s;
}
}
```

Enable the site:

```bash
sudo ln -s /etc/nginx/sites-available/text2trait /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```

## Environment Variables

If your application requires environment variables, set them before running:

```bash
export DATA_PATH=/path/to/data
export LOG_LEVEL=INFO
gunicorn wsgi_t2tfe:server --bind 127.0.0.1:8051 --workers 4
```

## Monitoring and Logs

Monitor the application:

```bash
# View logs
tail -f /var/log/text2trait/access.log
tail -f /var/log/text2trait/error.log

# Check service status
sudo systemctl status text2trait-frontend

# View systemd logs
sudo journalctl -u text2trait-frontend -f
```

## Performance Tuning

### Worker Count

The optimal number of workers depends on your server:

- CPU-bound applications: `(2 × CPU cores) + 1`
- I/O-bound applications: `(4 × CPU cores) + 1`

For the Dash application (mostly I/O-bound):

```bash
# For a 4-core server:
gunicorn wsgi_t2tfe:server --bind 127.0.0.1:8051 --workers 17
```

### Worker Class

For better async support, use the gevent worker class:

```bash
pip install gevent
gunicorn wsgi_t2tfe:server \
--bind 127.0.0.1:8051 \
--workers 4 \
--worker-class gevent \
--worker-connections 1000
```

## Troubleshooting

### Application won't start

1. Check Python path and dependencies:
```bash
python -c "from wsgi_t2tfe import server; print('OK')"
```

2. Check Gunicorn syntax:
```bash
gunicorn --check-config wsgi_t2tfe:server
```

3. Check logs for errors:
```bash
tail -f /var/log/text2trait/error.log
```

### High memory usage

Reduce the number of workers:

```bash
gunicorn wsgi_t2tfe:server --bind 127.0.0.1:8051 --workers 2
```

### Timeout errors

Increase the timeout:

```bash
gunicorn wsgi_t2tfe:server --bind 127.0.0.1:8051 --timeout 300
```

## Security Considerations

1. **Never expose Gunicorn directly to the internet** - Always use a reverse proxy like Nginx
2. **Use HTTPS** - Configure SSL/TLS in Nginx
3. **Firewall rules** - Restrict access to port 8051 to localhost only
4. **Keep dependencies updated** - Regularly update Python packages
5. **Use a dedicated user** - Don't run as root

## Additional Resources

- [Gunicorn Documentation](https://docs.gunicorn.org/)
- [Dash Deployment Guide](https://dash.plotly.com/deployment)
- [Nginx Documentation](https://nginx.org/en/docs/)
2 changes: 1 addition & 1 deletion text2trait_forntend_app/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@
# Application Entry Point
# ───────────────────────────────
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8050, debug=False)
app.run(host="127.0.0.1", port=8051, debug=False)
10 changes: 5 additions & 5 deletions text2trait_forntend_app/src/pages/home.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Home Page – GWAS-P
------------------
Home Page – Text2Trait
----------------------

This is the landing page for the GWAS-P application.
This is the landing page for the Text2Trait application.
It provides:
- An introductory description of the app.
- Search inputs for traits and (optionally) specific genes.
Expand All @@ -22,7 +22,7 @@
__name__,
path="/",
name="Home",
title="GWAS-P",
title="Text2Trait",
)


Expand All @@ -38,7 +38,7 @@
[
html.Img(
src=dash.get_asset_url("text2trait_logo.png"),
alt="GWAS-P logo",
alt="Text2Trait logo",
style={
"width": "200px",
"height": "200px",
Expand Down
6 changes: 3 additions & 3 deletions text2trait_forntend_app/src/pages/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Index Page – GWAS-P
-------------------
Index Page – Text2Trait
------------------------

This page provides a browsable index of:
- All traits in the knowledge graph.
Expand Down Expand Up @@ -186,7 +186,7 @@ def generate_trait_gene_tab() -> dash_table.DataTable:
# Page Layout
# ───────────────────────────────
layout = dbc.Container([
html.H2("GWAS-P Knowledge Graph Explorer", className="my-4"),
html.H2("Text2Trait Knowledge Graph Explorer", className="my-4"),
dbc.Row([
dbc.Col([
dbc.Tabs([
Expand Down
6 changes: 3 additions & 3 deletions text2trait_forntend_app/src/pages/questions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Questions Page – GWAS-P
-----------------------
Questions Page – Text2Trait
----------------------------

This page contains an FAQ section for common user questions
about the GWAS-P application.
about the Text2Trait application.
"""

import dash
Expand Down
8 changes: 4 additions & 4 deletions text2trait_forntend_app/src/pages/results.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Results Page – GWAS-P
----------------------
Results Page – Text2Trait
--------------------------

This page displays the GWAS-P results, including a trait-gene interaction
This page displays the Text2Trait results, including a trait-gene interaction
graph using Cytoscape, interactive tables for matched genes, and a side panel
for detailed gene information retrieved from NCBI.
"""
Expand Down Expand Up @@ -41,7 +41,7 @@
__name__,
path="/results",
name="Results",
title="GWAS-P Results"
title="Text2Trait Results"
)

# ───────────────────────────────
Expand Down
5 changes: 3 additions & 2 deletions text2trait_forntend_app/src/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "gwas-frontend-project"
name = "text2trait-frontend-project"
version = "0.1.0"
description = "Requirments for the frontend"
description = "Requirements for the frontend"
authors = [
]
readme = "README.md"
Expand All @@ -21,3 +21,4 @@ dependencies = [
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
package-mode = false
Loading