Skip to content

Commit

Permalink
feat: v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopr committed Jan 30, 2024
0 parents commit f104357
Show file tree
Hide file tree
Showing 118 changed files with 13,555 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# INFRA
TRAEFIK_URL="proxy.qsar.localhost"
TRAEFIK_BASIC_AUTH="admin:$$apr1$$gaS8tVEe$$MjqM8IlBvz2PRFEWcwha1/"
UI_URL="qsar.localhost"
PLAUSIBLE_URL="analytics.qsar.localhost"

# API
DATABASE_URL="postgresql://postgres:postgres@database:5432/qsar?schema=public"

# ANALYTICS
BASE_URL="https://${PLAUSIBLE_URL}"
SECRET_KEY_BASE=""
ENABLE_EMAIL_VERIFICATION=false

# UI
NEXT_PUBLIC_ANALYTICS_DOMAIN="${BASE_URL}"
NEXT_PUBLIC_ANALYTICS_HOST="${UI_URL}"
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release

on: workflow_dispatch

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-20.04
steps:
- name: Checkout Source Code
uses: actions/checkout@v2

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 20

- name: Install Yarn
run: corepack enable |
corepack prepare yarn@3.6.4 --activate

# Yarn dependencies cannot be cached until yarn is installed
# WORKAROUND: https://github.com/actions/setup-node/issues/531
- name: Extract Cached Dependencies
uses: actions/setup-node@v3
with:
cache: yarn

- name: Install Dependencies
run: yarn --immutable

- name: Set Git user to Actions Bot
run: |
git config --local user.name 'github-actions[bot]'
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Run Release
run: yarn release-it --ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.yarn
files
node_modules
report.txt
.env
.plausible.env
clickhouse
__pycache__

*.h5
*.hdf5

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint ${1}
20 changes: 20 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"git": {
"requireBranch": "main",
"commitMessage": "chore: release v${version}"
},
"github": {
"release": true
},
"plugins": {
"@release-it/bumper": {
"out": ["apps/ui/package.json", "packages/database/package.json"]
},
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"preset": {
"name": "conventionalcommits"
}
}
}
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"[prisma]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Prisma.prisma"
},
"cssVariables.lookupFiles": [
"**/*.css",
"**/*.scss",
"**/*.sass",
"**/*.less",
"node_modules/@mantine/core/esm/index.css"
],
"python.languageServer": "Jedi"
}
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@


## 0.1.1 (2023-12-20)


### Bug Fixes

* added 'pEC50 = ' to the start of the equation ([7bf8867](https://github.com/LABIOQUIM/plasmoqsar/commit/7bf88675e882fa3fa9c4a09295ade678c2c2e6f3))

## 0.1.0 (2023-12-20)


### Features

* added csv download, about page ([1bf73f1](https://github.com/LABIOQUIM/plasmoqsar/commit/1bf73f14e977bab82a04a29dae2bff3d9729d508))

## 0.0.9 (2023-12-19)


### Bug Fixes

* remove user name initial from avatar circle ([d686329](https://github.com/LABIOQUIM/plasmoqsar/commit/d686329d1b3a2d00ba396e42853294fc2e7109b2))

## 0.0.8 (2023-12-19)

## 0.0.7 (2023-12-18)


### Bug Fixes

* wrong path redirects ([30d17af](https://github.com/LABIOQUIM/plasmoqsar/commit/30d17af9bf321c80a9f0a66b749ad3c0e4fd3200))

## 0.0.6 (2023-12-18)

## 0.0.5 (2023-12-18)


### Bug Fixes

* submission form not accepting more than 8kb ([e8e19fb](https://github.com/LABIOQUIM/plasmoqsar/commit/e8e19fb582fe11af0b726e73c2f1e997bc8ac41d))

## 0.0.4 (2023-12-04)

## 0.0.3 (2023-12-04)


### Bug Fixes

* added alert for user already existing on registration ([ea3fbd3](https://github.com/LABIOQUIM/qsar/commit/ea3fbd32240ca7756f1ff4f66b1c5057b51307c8))

## 0.0.2 (2023-12-04)

## 0.0.1 (2023-12-04)
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# QSAR Model

### Setting up
This repository is a Monorepo, meaning all necessary code is here. You'll still need external tools to make it work.
1. Make sure you have [Docker](https://docker.com).
1. You'll also need the [nfsvol plugin](https://github.com/cirocosta/nfsvol) installed.
1. Then you can copy the file `.env.example` to `.env`. You don't need to change anything at this time.

#### Development
1. On Hold for now.

#### Production
If you want to simply instantiate and use, this is probably what you want.
1. Rewriting...

If everything went okay, you should be able to go to [localhost:3000](http://localhost:3000), register a new user and start using the app.
14 changes: 14 additions & 0 deletions apps/predictor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./app /code/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

# If running behind a proxy like Nginx or Traefik add --proxy-headers
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"]
7 changes: 7 additions & 0 deletions apps/predictor/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
45 changes: 45 additions & 0 deletions apps/predictor/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from fastapi import FastAPI, UploadFile
from contextlib import asynccontextmanager
from app.metrics import Metrics
from PIL import Image
from io import BytesIO
import numpy as np
import tensorflow as tf

model = {}

@asynccontextmanager
async def lifespan(app: FastAPI):
global model
dependencies = {
'precision': Metrics.precision,
'recall': Metrics.recall,
'f1_score': Metrics.f1_score,
'specificity': Metrics.specificity,
'npv': Metrics.npv,
'mcc': Metrics.mcc
}
model = tf.keras.models.load_model('/code/app/ResNet101V2_weights1.hdf5', custom_objects=dependencies)
yield
model = "deu merda"


app = FastAPI(lifespan=lifespan)


@app.post("/")
async def root(file: UploadFile):
contents = await file.read()
image = Image.open(BytesIO(contents))

img = image.resize((128, 128))

img = np.array(img) / 255.0
img = img[:, :, 0:3]
img = np.expand_dims(img, axis=0)

prediction = model.predict(img)
predicted = np.argmax(prediction, axis=1)

return int(predicted)

50 changes: 50 additions & 0 deletions apps/predictor/app/metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import random
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import tensorflow as tf
from keras import backend as K

class Metrics:

def recall(self, y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall_keras = true_positives / (possible_positives + K.epsilon())
return recall_keras


def precision(self, y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision_keras = true_positives / (predicted_positives + K.epsilon())
return precision_keras

def specificity(self, y_true, y_pred):
tn = K.sum(K.round(K.clip((1 - y_true) * (1 - y_pred), 0, 1)))
fp = K.sum(K.round(K.clip((1 - y_true) * y_pred, 0, 1)))
return tn / (tn + fp + K.epsilon())

def f1_score(self, y_true, y_pred):
p = self.precision(y_true, y_pred)
r = self.recall(y_true, y_pred)
return 2 * ((p * r) / (p + r + K.epsilon()))

# Netavie Predictive Error
def npv(self, y_true, y_pred):
tn = K.sum(K.round(K.clip((1 - y_true) * (1 - y_pred), 0, 1)))
fn = K.sum(K.round(K.clip(y_true * (1 - y_pred), 0, 1)))
return tn / (tn + fn + K.epsilon())

# Matthews Correlation_Coefficient
def mcc(self, y_true, y_pred):
tp = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
tn = K.sum(K.round(K.clip((1 - y_true) * (1 - y_pred), 0, 1)))
fp = K.sum(K.round(K.clip((1 - y_true) * y_pred, 0, 1)))
fn = K.sum(K.round(K.clip(y_true * (1 - y_pred), 0, 1)))

num = tp * tn - fp * fn
den = (tp + fp) * (tp + fn) * (tn + fp) * (tn + fn)
return num / K.sqrt(den + K.epsilon())
5 changes: 5 additions & 0 deletions apps/predictor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "predictor",
"version": "0.0.0",
"packageManager": "yarn@3.7.0"
}
Loading

0 comments on commit f104357

Please sign in to comment.