Skip to content

Commit

Permalink
✅ Roboflow API integration done
Browse files Browse the repository at this point in the history
  • Loading branch information
SkalskiP committed Dec 20, 2022
1 parent 6aa8cc9 commit 3202a93
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const App: React.FC<IProps> = (
const isAILoaded = isObjectDetectorLoaded
|| isPoseDetectionLoaded
|| isYOLOV5ObjectDetectorLoaded
|| (roboflowAPIDetails.model !== '' && roboflowAPIDetails.key !== '')
|| (roboflowAPIDetails.model !== '' && roboflowAPIDetails.key !== '' && roboflowAPIDetails.status)

return (
<div className={classNames('App', {'AI': isAILoaded})} draggable={false}
Expand Down
2 changes: 1 addition & 1 deletion src/ai/RoboflowAPIObjectDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class RoboflowAPIObjectDetector {
const activeImageData: ImageData = LabelsSelector.getActiveImageData();

const wrappedOnFailure = () => {
store.dispatch(updateRoboflowAPIDetails({model: '', key: ''}));
store.dispatch(updateRoboflowAPIDetails({status: false, model: '', key: ''}));
onFailure()
}

Expand Down
5 changes: 0 additions & 5 deletions src/logic/actions/AIRoboflowAPIObjectDetectionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import { AIActions } from './AIActions';
import { updateSuggestedLabelList } from '../../store/ai/actionCreators';

export class AIRoboflowAPIObjectDetectionActions {
public static detectRectsForActiveImage(): void {
const activeImageData: ImageData = LabelsSelector.getActiveImageData();
AIRoboflowAPIObjectDetectionActions.detectRects(activeImageData)
}

public static detectRects(imageData: ImageData): void {
if (imageData.isVisitedByRoboflowAPI || !AISelector.isRoboflowAPIModelLoaded())
return;
Expand Down
22 changes: 9 additions & 13 deletions src/logic/initializer/AppInitializer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {updateWindowSize} from "../../store/general/actionCreators";
import {ContextManager} from "../context/ContextManager";
import {store} from "../../index";
import {PlatformUtil} from "../../utils/PlatformUtil";
import {PlatformModel} from "../../staticModels/PlatformModel";
import {EventType} from "../../data/enums/EventType";
import {GeneralSelector} from "../../store/selectors/GeneralSelector";
import {EnvironmentUtil} from "../../utils/EnvironmentUtil";
import {updateWindowSize} from '../../store/general/actionCreators';
import {ContextManager} from '../context/ContextManager';
import {store} from '../../index';
import {PlatformUtil} from '../../utils/PlatformUtil';
import {PlatformModel} from '../../staticModels/PlatformModel';
import {EventType} from '../../data/enums/EventType';
import {GeneralSelector} from '../../store/selectors/GeneralSelector';
import {EnvironmentUtil} from '../../utils/EnvironmentUtil';

export class AppInitializer {
public static inti():void {
Expand Down Expand Up @@ -37,11 +37,7 @@ export class AppInitializer {
};

private static disableUnwantedKeyBoardBehaviour = (event: KeyboardEvent) => {
if (PlatformModel.isMac && event.metaKey) {
event.preventDefault();
}

if (["=", "+", "-"].includes(event.key)) {
if (['=', '+', '-'].includes(event.key)) {
if (event.ctrlKey || (PlatformModel.isMac && event.metaKey)) {
event.preventDefault();
}
Expand Down
1 change: 1 addition & 0 deletions src/store/ai/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const initialState: AIState = {
isYOLOV5ObjectDetectorLoaded: false,
isPoseDetectorLoaded: false,
roboflowAPIDetails: {
status: false,
model: '',
key: ''
},
Expand Down
1 change: 1 addition & 0 deletions src/store/ai/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Action} from '../Actions';

export type RoboflowAPIDetails = {
status: boolean,
model: string,
key: string
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/selectors/AISelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AISelector {
public static isRoboflowAPIModelLoaded(): boolean {
const roboflowAPIDetails = store.getState().ai.roboflowAPIDetails;
return (
roboflowAPIDetails.model !== '' && roboflowAPIDetails.key !== ''
roboflowAPIDetails.model !== '' && roboflowAPIDetails.key !== '' && roboflowAPIDetails.status
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ import { NotificationsDataMap } from '../../../data/info/NotificationsData';
import { Notification } from '../../../data/enums/Notification';
import './ConnectInferenceServerPopup.scss'
import { StyledTextField } from '../../Common/StyledTextField/StyledTextField';
import { RoboflowAPIDetails } from '../../../store/ai/types';
import { AIActionTypes, RoboflowAPIDetails } from '../../../store/ai/types';
import { RoboflowAPIObjectDetector } from '../../../ai/RoboflowAPIObjectDetector';
import { ClipLoader } from 'react-spinners';
import { CSSHelper } from '../../../logic/helpers/CSSHelper';
import { updateRoboflowAPIDetails } from '../../../store/ai/actionCreators';
import { AIActions } from '../../../logic/actions/AIActions';
import { ImageRepository } from '../../../logic/imageRepository/ImageRepository';
import { ImageData } from '../../../store/labels/types';
import { LabelsSelector } from '../../../store/selectors/LabelsSelector';

interface IProps {
roboflowAPIDetails: RoboflowAPIDetails;
submitNewNotificationAction: (notification: INotification) => NotificationsActionType;
updateRoboflowAPIDetailsAction: (roboflowAPIDetails: RoboflowAPIDetails) => AIActionTypes;
}

const ConnectInferenceServerPopup: React.FC<IProps> = (
{
roboflowAPIDetails,
submitNewNotificationAction
submitNewNotificationAction,
updateRoboflowAPIDetailsAction
}
) => {
// general
Expand Down Expand Up @@ -64,7 +71,15 @@ const ConnectInferenceServerPopup: React.FC<IProps> = (
if (disableAcceptButton()) return;

const onSuccess = () => {
updateRoboflowAPIDetailsAction({
status: true,
model: roboflowModel,
key: roboflowKey
})
PopupActions.close();

const activeImageData: ImageData = LabelsSelector.getActiveImageData();
AIActions.detect(activeImageData.id, ImageRepository.getById(activeImageData.id));
}

const onFailure = () => {
Expand All @@ -75,6 +90,7 @@ const ConnectInferenceServerPopup: React.FC<IProps> = (

setModelIsLoadingStatus(true);
RoboflowAPIObjectDetector.loadModel({
status: false,
model: roboflowModel,
key: roboflowKey
}, onSuccess, onFailure)
Expand Down Expand Up @@ -178,7 +194,8 @@ const ConnectInferenceServerPopup: React.FC<IProps> = (
}

const mapDispatchToProps = {
submitNewNotificationAction: submitNewNotification
submitNewNotificationAction: submitNewNotification,
updateRoboflowAPIDetailsAction: updateRoboflowAPIDetails
};

const mapStateToProps = (state: AppState) => ({
Expand Down

0 comments on commit 3202a93

Please sign in to comment.