Skip to content

Commit

Permalink
Improvements (#187)
Browse files Browse the repository at this point in the history
* changes utility direction

* order metrics

* order metrics

* add new profile page

* modify badges

* get the active tasks per user

* get the active tasks per user

* Fix hf

* info for models

* new user profile page

* new user profile page

* change label community

* add user stats

* stats endpoint

* add task proposals

* add task proposals

* Implement new models

* Debug HF

* model all info

* websocket

* nibbler ws implementation

* nibbler ws implementation

* new login, model, and profile page

* upload number of generated images

* change amount of generated images

* add longdesc model

* update model info

* update model info

* model validation

* authenticate methods

* new auth

* model info

* Fix Typos

* Typo fix

* typo

* ensure that there's is a file

* solve publish model bug

* new logic validation

* just moving folders

* solve a linter problem

* fixing bugs

* add no double validation

* add no fooling

* add no fooling

* destructure validate samples

* bug in orm

* fix problem with login

* fix typos

* New packages

* Merge changes

* Fix forbidden images

* Additional TS/JS packages

* add control error

---------

Co-authored-by: remg1997 <rafael.mosquera@factored.ai>
  • Loading branch information
Ciroye and remg1997 authored Aug 9, 2023
1 parent c52a97f commit 19ae746
Show file tree
Hide file tree
Showing 203 changed files with 4,878 additions and 1,069 deletions.
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-ast
Expand All @@ -31,7 +31,7 @@ repos:
language: system

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.7
rev: v1.5.1
hooks:
- id: insert-license
files: \.py$
Expand All @@ -45,31 +45,31 @@ repos:
- docs/license_header.txt
- --comment-style
- /*| *| */
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/asottile/pyupgrade
rev: v2.2.1
rev: v3.10.1
hooks:
- id: pyupgrade
args: ['--py36-plus']

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
exclude: ^website

- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.3.0
rev: v3.0.0
hooks:
- id: prettier
files: \.[jt]sx?$
Expand All @@ -84,7 +84,7 @@ repos:
- stylelint-config-standard@20.0.0

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.21.0
rev: v8.46.0
hooks:
- id: eslint
args: [--fix --silent]
Expand Down
8 changes: 4 additions & 4 deletions backend/app/api/endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import APIRouter, Depends
from fastapi.security import OAuth2PasswordRequestForm

from app.domain.auth.authentication import Login
from app.domain.auth.authentication import LoginService
from app.domain.schemas.auth.auth import (
CreateUserRequest,
CreateUserResponse,
Expand All @@ -19,14 +19,14 @@

@router.post("/login", response_model=LoginResponse)
async def login(model: OAuth2PasswordRequestForm = Depends()):
return Login().login(model.username, model.password)
return LoginService().login(model.username, model.password)


@router.post("/create_user", response_model=CreateUserResponse)
async def create_user(model: CreateUserRequest):
return Login().create_user(model.email, model.password, model.username)
return LoginService().create_user(model.email, model.password, model.username)


@router.post("/is_admin_or_owner", response_model=bool)
async def is_admin_or_owner(model: IsAdminOrOwnerRequest):
return Login().is_admin_or_owner(model.user_id, model.task_id)
return LoginService().is_admin_or_owner(model.user_id, model.task_id)
35 changes: 33 additions & 2 deletions backend/app/api/endpoints/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from fastapi import APIRouter
import asyncio
import json

from fastapi import APIRouter, WebSocket
from fastapi.responses import JSONResponse
from sse_starlette.sse import EventSourceResponse

from app.domain.schemas.base.context import (
GetContextRequest,
Expand All @@ -26,7 +31,33 @@ async def get_context_configuration(task_id: int):
return context_config


@router.websocket("/ws/get_generative_contexts")
async def websocket_generative_context(websocket: WebSocket):
await websocket.accept()
model_info = await websocket.receive_json()
model_info = dict(model_info)
for _ in range(4):
data = ContextService().get_generative_contexts(
model_info["type"], model_info["artifacts"]
)
await websocket.send_json(data)
await websocket.close()


@router.post("/get_generative_contexts")
async def get_generative_contexts(model: GetGenerativeContextRequest):
image_list = ContextService().get_generative_contexts(model.type, model.artifacts)
return image_list
return JSONResponse(content=image_list, headers={"Cache-Control": "private"})


@router.post("/stream")
async def stream_images(model_info: GetGenerativeContextRequest):
async def event_generator():
for _ in range(2):
data = ContextService().get_generative_contexts(
model_info.type, model_info.artifacts
)
yield json.dumps(data)
await asyncio.sleep(1)

return EventSourceResponse(event_generator())
4 changes: 2 additions & 2 deletions backend/app/api/endpoints/base/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DownloadAllExamplesRequest,
DownloadExamplesRequest,
GetExampleRequest,
PartiallyCreationExampleGenerativeRequest,
PartialCreationExampleRequest,
UpdateCreationExampleGenerativeRequest,
ValidateExampleRequest,
)
Expand Down Expand Up @@ -53,7 +53,7 @@ def validate_example(model: ValidateExampleRequest):

@router.post("/partial_creation_generative_example", response_model={})
def partial_creation_generative_example(
model: PartiallyCreationExampleGenerativeRequest,
model: PartialCreationExampleRequest,
):
return ExampleService().partial_creation_generative_example(
model.example_info,
Expand Down
43 changes: 36 additions & 7 deletions backend/app/api/endpoints/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ModelPredictionPerDatasetRequest,
SingleModelEvaluationRequest,
SingleModelEvaluationResponse,
UpdateModelInfoRequest,
UploadModelToS3AndEvaluateRequest,
)
from app.domain.services.base.model import ModelService
Expand Down Expand Up @@ -89,9 +90,9 @@ def initiate_lambda_models() -> None:
return ModelService().initiate_lambda_models()


@router.post("/get_model_prediction_per_dataset")
def get_model_prediction_per_dataset(model: ModelPredictionPerDatasetRequest):
file_name = ModelService().get_model_prediction_per_dataset(
@router.post("/get_model_prediction_by_dataset")
def get_model_prediction_by_dataset(model: ModelPredictionPerDatasetRequest):
file_name = ModelService().get_model_prediction_by_dataset(
model.user_id, model.model_id, model.dataset_id
)
return FileResponse(
Expand All @@ -101,9 +102,9 @@ def get_model_prediction_per_dataset(model: ModelPredictionPerDatasetRequest):
)


@router.get("/get_amount_of_models_per_task/{task_id}", response_model=int)
def get_amount_of_models_per_task(task_id: int):
return ModelService().get_amount_of_models_per_task(task_id)
@router.get("/get_amount_of_models_by_task/{task_id}", response_model=int)
def get_amount_of_models_by_task(task_id: int):
return ModelService().get_amount_of_models_by_task(task_id)


@router.post("/upload_prediction_to_s3")
Expand All @@ -117,7 +118,6 @@ def upload_prediction_to_s3(

@router.post("/conversation_with_buffer_memory")
def conversation_with_buffer_memory(model: ConversationWithBufferMemoryRequest):
print("model.history", model.history)
return ModelService().conversation_with_buffer_memory(
model.history, model.model_name, model.provider, model.prompt, model.num_answers
)
Expand All @@ -126,3 +126,32 @@ def conversation_with_buffer_memory(model: ConversationWithBufferMemoryRequest):
@router.get("/update_model_status/{model_id}")
def update_model_status(model_id: int):
return ModelService().update_model_status(model_id)


@router.get("/get_models_by_user_id/{user_id}")
def get_models_by_user_id(user_id: int):
return ModelService().get_models_by_user_id(user_id)


@router.get("/delete_model/{model_id}")
def delete_model(model_id: int):
return ModelService().delete_model(model_id)


@router.get("/get_all_model_info_by_id/{model_id}")
def get_all_model_info_by_id(model_id: int):
return ModelService().get_all_model_info_by_id(model_id)


@router.post("/update_model_info")
def update_model_info(model: UpdateModelInfoRequest):
return ModelService().update_model_info(
model.model_id,
model.name,
model.desc,
model.longdesc,
model.params,
model.languages,
model.license,
model.source_url,
)
6 changes: 3 additions & 3 deletions backend/app/api/endpoints/base/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
router = APIRouter()


@router.get("/get_maximun_principal_score_per_task/{task_id}", response_model={})
async def get_maximun_principal_score_per_task(task_id: int):
return ScoreService().get_maximun_principal_score_per_task(task_id)
@router.get("/get_maximun_principal_score_by_task/{task_id}", response_model={})
async def get_maximun_principal_score_by_task(task_id: int):
return ScoreService().get_maximun_principal_score_by_task(task_id)
5 changes: 5 additions & 0 deletions backend/app/api/endpoints/base/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ async def get_challenges_types():
@router.get("/get_tasks_with_samples_created_by_user/{user_id}", response_model={})
async def get_tasks_with_samples_created_by_user(user_id: int):
return TaskService().get_tasks_with_samples_created_by_user(user_id)


@router.get("/get_active_tasks_by_user_id/{user_id}", response_model={})
async def get_active_tasks_by_user_id(user_id: str):
return TaskService().get_active_tasks_by_user_id(user_id)
24 changes: 24 additions & 0 deletions backend/app/api/endpoints/base/task_proposals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) MLCommons and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from fastapi import APIRouter

from app.domain.services.base.task_proposals import TaskProposalService


router = APIRouter()


@router.get("/validate_no_duplicate_task_code/{task_code}", response_model={})
async def validate_no_duplicate_task_code(task_code: str):
return TaskProposalService().validate_no_duplicate_task_code(task_code)


@router.post("/add_task_proposal", response_model={})
async def add_task_proposal(
user_id: int, task_code: str, name: str, desc: str, longdesc: str
):
return TaskProposalService().add_task_proposal(
user_id, task_code, name, desc, longdesc
)
32 changes: 32 additions & 0 deletions backend/app/api/endpoints/base/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) MLCommons and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from fastapi import APIRouter

from app.domain.auth.authentication import LoginService
from app.domain.schemas.auth.auth import CreateUserRequest, LoginRequest
from app.domain.services.base.user import UserService


router = APIRouter()


@router.get("/get_user_with_badges/{user_id}", response_model={})
async def get_task_id_by_task_code(user_id: str):
return UserService().get_user_with_badges(user_id)


@router.get("/get_stats_by_user_id/{user_id}", response_model={})
async def get_stats_by_user_id(user_id: str):
return UserService().get_stats_by_user_id(user_id)


@router.post("/authenticate")
async def authenticate(model: LoginRequest):
return LoginService().login(model.email, model.password)


@router.post("/create_user")
async def create_user(model: CreateUserRequest):
return LoginService().create_user(model.email, model.password, model.username)
11 changes: 7 additions & 4 deletions backend/app/domain/auth/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
user_with_email_already_exists,
)
from app.domain.services.base.user import UserService
from app.infrastructure.repositories.badge import BadgeRepository
from app.infrastructure.repositories.taskuserpermission import (
TaskUserPermissionRepository,
)


class Login:
class LoginService:
def __init__(self) -> None:
self.AUTH_JWT_SECRET_KEY = os.getenv("AUTH_JWT_SECRET_KEY")
self.ACCESS_TOKEN_EXPIRE_MINUTES = os.getenv("AUTH_ACCESS_TOKEN_EXPIRE_MINUTES")
Expand All @@ -30,6 +31,7 @@ def __init__(self) -> None:
self.AUTH_HASH_ALGORITHM = os.getenv("AUTH_HASH_ALGORITHM")
self.users_service = UserService()
self.task_user_permission_repository = TaskUserPermissionRepository()
self.badges_repository = BadgeRepository()

def get_hashed_password(self, password: str) -> str:
return generate_password_hash(password)
Expand Down Expand Up @@ -70,7 +72,8 @@ def create_user(self, email: str, password: str, username: str) -> dict:
if user:
user_with_email_already_exists(email)
password = self.get_hashed_password(password)
return self.users_service.create_user(email, password, username)
user_id = self.users_service.create_user(email, password, username)["id"]
self.badges_repository.add_badge(user_id, "WELCOME_NOOB")

def login(self, email: str, password: str) -> dict:
user = self.users_service.get_by_email(email)
Expand All @@ -80,8 +83,8 @@ def login(self, email: str, password: str) -> dict:
if not self.verify_password(password, hashed_pass):
password_is_incorrect()
return {
"access_token": self.create_access_token(user["email"]),
"token_type": "bearer",
"token": self.create_access_token(user["email"]),
"user": user,
}

def is_admin_or_owner(self, user_id: int, task_id: int):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Hi there

Your model $name has failed evaluating. Please check your model and try again. If you think this is a mistake, please contact
the task organizer.

Thanks,

The Dynabench Team
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Hi there

Your model $name has been successfully evaluated.
You can find and publish the model at https://dynabench.org/models/$model_id.

Thanks,

The Dynabench Team
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Greetings,

You're task $name with the code $code has been successfully created with the following description: $desc.

Thanks,

The Dynabench Team
2 changes: 1 addition & 1 deletion backend/app/domain/schemas/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CreateUserResponse(BaseModel):


class LoginRequest(BaseModel):
username: EmailStr
email: EmailStr
password: str


Expand Down
2 changes: 1 addition & 1 deletion backend/app/domain/schemas/base/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CreateExampleRequest(BaseModel):
tag: Optional[str] = "generative"


class PartiallyCreationExampleGenerativeRequest(BaseModel):
class PartialCreationExampleRequest(BaseModel):
example_info: dict
context_id: int
user_id: int
Expand Down
Loading

0 comments on commit 19ae746

Please sign in to comment.