From 3e51b2efe33a577dce9421190cf518f83b3ee946 Mon Sep 17 00:00:00 2001 From: koji Date: Thu, 16 Nov 2023 14:48:47 -0500 Subject: [PATCH 1/9] fix(app, ccomponent): dqa device detail deck configurator dqa device detail deck configurator close RAUT-831 --- .../assets/localization/en/device_details.json | 11 ++++++----- .../DeviceDetailsDeckConfiguration.test.tsx | 8 ++++++++ .../DeviceDetailsDeckConfiguration/index.tsx | 18 ++++++++++++++---- .../StagingAreaConfigFixture.tsx | 6 +++++- .../DeckConfigurator/TrashBinConfigFixture.tsx | 6 +++++- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/src/assets/localization/en/device_details.json b/app/src/assets/localization/en/device_details.json index 517b24894f0..2a0c80d349c 100644 --- a/app/src/assets/localization/en/device_details.json +++ b/app/src/assets/localization/en/device_details.json @@ -33,8 +33,8 @@ "current_temp": "Current: {{temp}} °C", "current_version": "Current Version", "deck_cal_missing": "Pipette Offset calibration missing. Calibrate deck first.", - "deck_configuration_is_not_available_when_run_is_in_progress": "Deck configuration is not available when run is in progress", "deck_configuration_is_not_available_when_robot_is_busy": "Deck configuration is not available when the robot is busy", + "deck_configuration_is_not_available_when_run_is_in_progress": "Deck configuration is not available when run is in progress", "deck_configuration": "deck configuration", "deck_fixture_setup_instructions": "Deck fixture setup instructions", "deck_fixture_setup_modal_bottom_description_desktop": "For detailed instructions for different types of fixtures, scan the QR code or go to the link below.", @@ -79,13 +79,13 @@ "magdeck_gen1_height": "Height: {{height}}", "magdeck_gen2_height": "Height: {{height}} mm", "max_engage_height": "Max Engage Height", + "missing_fixture": "missing {{num}} fixture", + "missing_fixtures_plural": "missing {{count}} fixtures", "missing_hardware": "missing hardware", - "missing_module_plural": "missing {{count}} modules", - "missing_module": "missing {{num}} module", "missing_instrument": "missing {{num}} instrument", "missing_instruments_plural": "missing {{count}} instruments", - "missing_fixture": "missing {{num}} fixture", - "missing_fixtures_plural": "missing {{count}} fixtures", + "missing_module_plural": "missing {{count}} modules", + "missing_module": "missing {{num}} module", "module_actions_unavailable": "Module actions unavailable while protocol is running", "module_calibration_required_no_pipette_attached": "Module calibration required. Attach a pipette before running module calibration.", "module_calibration_required_update_pipette_FW": "Update pipette firmware before proceeding with required module calibration.", @@ -98,6 +98,7 @@ "mount": "{{side}} Mount", "na_speed": "Target: N/A", "na_temp": "Target: N/A", + "no_deck_fixtures": "No deck fixtures", "no_protocol_runs": "No protocol runs yet!", "no_protocols_found": "No protocols found", "no_recent_runs_description": "After you run some protocols, they will appear here.", diff --git a/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx b/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx index 3965297c1a3..77101c421ce 100644 --- a/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx +++ b/app/src/organisms/DeviceDetailsDeckConfiguration/__tests__/DeviceDetailsDeckConfiguration.test.tsx @@ -125,4 +125,12 @@ describe('DeviceDetailsDeckConfiguration', () => { getByText('Deck configuration is not available when the robot is busy') getByText('disabled mock DeckConfigurator') }) + + it('should render no deck fixtures, if deck configs are not set', () => { + when(mockUseDeckConfigurationQuery) + .calledWith() + .mockReturnValue([] as any) + const [{ getByText }] = render(props) + getByText('No deck fixtures') + }) }) diff --git a/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx b/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx index e925a0d057f..f0c119117cf 100644 --- a/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx +++ b/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx @@ -190,8 +190,8 @@ export function DeviceDetailsDeckConfiguration({ {t('location')} {t('fixture')} - {fixtureDisplayList.map(fixture => { - return ( + {fixtureDisplayList.length > 0 ? ( + fixtureDisplayList.map(fixture => ( - ) - })} + )) + ) : ( + + {t('no_deck_fixtures')} + + )} diff --git a/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx index d98cfbfdc13..1f4110bcc60 100644 --- a/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx @@ -60,7 +60,11 @@ export function StagingAreaConfigFixture( foreignObjectProps={{ flex: '1' }} > - + {stagingAreaDef.metadata.displayName} {handleClickRemove != null ? ( diff --git a/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx index f47132ebe33..1610c0a3921 100644 --- a/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx @@ -66,7 +66,11 @@ export function TrashBinConfigFixture( foreignObjectProps={{ flex: '1' }} > - + {trashBinDef.metadata.displayName} {handleClickRemove != null ? ( From de63008f7396d69aa0bd958fceaffd30b53b12fa Mon Sep 17 00:00:00 2001 From: koji Date: Thu, 16 Nov 2023 17:41:16 -0500 Subject: [PATCH 2/9] address the comment --- .../DeckConfigurator/EmptyConfigFixture.tsx | 25 ++--------- .../StagingAreaConfigFixture.tsx | 31 ++++---------- .../TrashBinConfigFixture.tsx | 31 ++++---------- .../WasteChuteConfigFixture.tsx | 42 ++++++++----------- .../DeckConfigurator/constants.ts | 23 ++++++++++ .../hardware-sim/DeckConfigurator/index.tsx | 15 +++++++ 6 files changed, 75 insertions(+), 92 deletions(-) create mode 100644 components/src/hardware-sim/DeckConfigurator/constants.ts diff --git a/components/src/hardware-sim/DeckConfigurator/EmptyConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/EmptyConfigFixture.tsx index a80fac8112b..c0294942b69 100644 --- a/components/src/hardware-sim/DeckConfigurator/EmptyConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/EmptyConfigFixture.tsx @@ -6,27 +6,10 @@ import { Btn, Flex } from '../../primitives' import { ALIGN_CENTER, DISPLAY_FLEX, JUSTIFY_CENTER } from '../../styles' import { BORDERS, COLORS } from '../../ui-style-constants' import { RobotCoordsForeignObject } from '../Deck/RobotCoordsForeignObject' +import { FIXTURE_HEIGHT, SINGLE_SLOT_FIXTURE_WIDTH } from './constants' import type { Cutout, DeckDefinition } from '@opentrons/shared-data' -// TODO: replace stubs with JSON definitions when available -const standardSlotDef = { - schemaVersion: 1, - version: 1, - namespace: 'opentrons', - metadata: { - displayName: 'standard slot', - }, - parameters: { - loadName: 'standard_slot', - }, - boundingBox: { - xDimension: 246.5, - yDimension: 106.0, - zDimension: 0, - }, -} - interface EmptyConfigFixtureProps { deckDefinition: DeckDefinition fixtureLocation: Cutout @@ -56,12 +39,10 @@ export function EmptyConfigFixture( const yAdjustment = -10 const y = ySlotPosition + yAdjustment - const { xDimension, yDimension } = standardSlotDef.boundingBox - return ( - {stagingAreaDef.metadata.displayName} + {STAGING_AREA_DISPLAY_NAME} {handleClickRemove != null ? ( - {trashBinDef.metadata.displayName} + {TRASH_BIN_DISPLAY_NAME} {handleClickRemove != null ? ( void + hasStagingAreas?: boolean } export function WasteChuteConfigFixture( props: WasteChuteConfigFixtureProps ): JSX.Element { - const { deckDefinition, handleClickRemove, fixtureLocation } = props + const { + deckDefinition, + handleClickRemove, + fixtureLocation, + hasStagingAreas = false, + } = props const wasteChuteSlot = deckDefinition.locations.cutouts.find( slot => slot.id === fixtureLocation @@ -48,12 +42,12 @@ export function WasteChuteConfigFixture( const yAdjustment = -10 const y = ySlotPosition + yAdjustment - const { xDimension, yDimension } = wasteChuteDef.boundingBox - return ( - {wasteChuteDef.metadata.displayName} + {WASTE_CHUTE_DISPLAY_NAME} {handleClickRemove != null ? ( cutoutFixtureId != null && WASTE_CHUTE_FIXTURES.includes(cutoutFixtureId) ) + const wasteChuteStagingAreaFixtures = configurableDeckConfig.filter( + ({ cutoutFixtureId }) => + cutoutFixtureId != null && + WASTE_CHUTE_STAGING_AREA_FIXTURES.includes(cutoutFixtureId) + ) const emptyFixtures = readOnly ? [] : configurableDeckConfig.filter( @@ -117,6 +123,15 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { fixtureLocation={cutoutId} /> ))} + {wasteChuteStagingAreaFixtures.map(({ cutoutId }) => ( + + ))} {trashBinFixtures.map(({ cutoutId }) => ( Date: Fri, 17 Nov 2023 11:01:41 -0500 Subject: [PATCH 3/9] address comments --- app.py | 104 ++++++++++++++++++ .../StagingAreaConfigFixture.tsx | 4 +- .../TrashBinConfigFixture.tsx | 4 +- .../WasteChuteConfigFixture.tsx | 2 +- .../DeckConfigurator/constants.ts | 19 +--- .../src/ui-style-constants/typography.ts | 9 +- 6 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 00000000000..f01023bce2d --- /dev/null +++ b/app.py @@ -0,0 +1,104 @@ +import gradio as gr +import requests +import uuid +import os + +def string_to_binary(input_string): + binary_string = ''.join(format(ord(char), '08b') for char in input_string) + return binary_string + + +def upload_protocol(protocol_name): + robot_ip = "localhost" + # robot_url = "https://baxin-ot-analysis.hf.space" + endpoint = f"http://{robot_ip}:31950/protocols" + # protocol_name = generate_unique_name() + + protocol_file = open(protocol_name, "rb") + files = { + "files": (protocol_name, protocol_file), + } + + + headers = {"Opentrons-Version": "3"} + response = requests.post(endpoint, headers=headers, files=files) + response_data = response.json() + + protocol_file.close() + if os.path.exists(protocol_name): + # if the protocol file is existing, remove it + os.remove(protocol_name) + + if 'data' in response_data: + response_data = response.json() + protocol_id = response_data["data"]["id"] + analysis_result=response_data["data"]["analyses"] + analysis_id = response_data["data"]["analysisSummaries"][0]["id"] + analysis_status = response_data["data"]["analysisSummaries"][0]["status"] + print(protocol_id) + print(analysis_result) + print(analysis_id) + print(analysis_status) + return f"success\n protocol_id:{protocol_id}\n analysis_id:{analysis_id}" + else: + print("analysis error") + error_id = response_data["errors"][0]['id'] + error_code = response_data["errors"][0]["errorCode"] + error_detail = response_data["errors"][0]['detail'] + print(error_id) + print(error_code) + print(error_detail) + return f"{error_id}\n{error_code}\n{error_detail}" + +def generate_unique_name(): + unique_name = str(uuid.uuid4()) + ".py" + return unique_name + +def send_post_request(payload): + url = "https://baxin-simulator.hf.space/protocol" + protocol_name = generate_unique_name() + data = {"name": protocol_name, "content": payload} + headers = {"Content-Type": "application/json"} + + response = requests.post(url, json=data, headers=headers) + + if response.status_code != 200: + print("Error: " + response.text) + return "Error: " + response.text + + # Check the response before returning it + response_data = response.json() + if "error_message" in response_data: + print("Error in response:", response_data["error_message"]) + return response_data["error_message"] + elif "protocol_name" in response_data: + print("Protocol executed successfully. Run log:", response_data["run_log"]) + return response_data["run_log"] + else: + print("Unexpected response:", response_data) + return "Unexpected response" + + + + +def send_message(text, chatbot): + # Send POST request and get response +# response = send_post_request(text) +# binary_protocol = string_to_binary(text) + protocol_name = generate_unique_name() + with open(protocol_name, "w") as file: + file.write(text) + + response = upload_protocol(protocol_name) + # Update chatbot with response + chatbot.append(("opentrons analysis result", response)) + return chatbot + +with gr.Blocks() as app: + textbox = gr.Textbox() + send_button = gr.Button(value="Send") + chatbot = gr.Chatbot() + clear_button = gr.ClearButton([textbox, chatbot]) + send_button.click(send_message, [textbox, chatbot], [chatbot]) + +app.launch() diff --git a/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx index 5063bc3310a..28f0b321041 100644 --- a/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx @@ -46,9 +46,7 @@ export function StagingAreaConfigFixture( > {STAGING_AREA_DISPLAY_NAME} diff --git a/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx index 52864115188..9f1d968f288 100644 --- a/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx @@ -52,9 +52,7 @@ export function TrashBinConfigFixture( > {TRASH_BIN_DISPLAY_NAME} diff --git a/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx index 21f23ee2749..4d2491eed3d 100644 --- a/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx @@ -54,7 +54,7 @@ export function WasteChuteConfigFixture( foreignObjectProps={{ flex: '1' }} > - + {WASTE_CHUTE_DISPLAY_NAME} {handleClickRemove != null ? ( diff --git a/components/src/hardware-sim/DeckConfigurator/constants.ts b/components/src/hardware-sim/DeckConfigurator/constants.ts index ef1552b96b7..034d257f900 100644 --- a/components/src/hardware-sim/DeckConfigurator/constants.ts +++ b/components/src/hardware-sim/DeckConfigurator/constants.ts @@ -3,21 +3,4 @@ export const SINGLE_SLOT_FIXTURE_WIDTH = 246.5 export const STAGING_AREA_FIXTURE_WIDTH = 318.5 export const STAGING_AREA_DISPLAY_NAME = 'Staging area' export const TRASH_BIN_DISPLAY_NAME = 'Trash bin' -export const WASTE_CHUTE_DISPLAY_NAME = 'Waste chute' - -export const wasteChuteDef = { - schemaVersion: 1, - version: 1, - namespace: 'opentrons', - metadata: { - displayName: 'Waste chute', - }, - parameters: { - loadName: 'trash_chute', - }, - boundingBox: { - xDimension: 286.5, - yDimension: FIXTURE_HEIGHT, - zDimension: 0, - }, -} +export const WASTE_CHUTE_DISPLAY_NAME = 'Waste chute' \ No newline at end of file diff --git a/components/src/ui-style-constants/typography.ts b/components/src/ui-style-constants/typography.ts index 461e223d0ff..d480e7902dc 100644 --- a/components/src/ui-style-constants/typography.ts +++ b/components/src/ui-style-constants/typography.ts @@ -217,6 +217,12 @@ export const smallBodyTextBold = css` font-weight: ${fontWeightBold}; ` +export const smallBodyTextSemiBold = css` +font-size: ${fontSize20}; +line-height: ${lineHeight24}; +font-weight: ${fontWeightSemiBold}; +` + export const smallBodyTextRegular = css` font-size: ${fontSize20}; line-height: ${lineHeight24}; @@ -232,6 +238,7 @@ export const darkLinkH4SemiBold = css` color: ${COLORS.darkBlackEnabled}; } ` + export const darkLinkLabelSemiBold = css` font-size: ${fontSizeLabel}; font-weight: ${fontWeightSemiBold}; @@ -248,4 +255,4 @@ export const darkLinkLabelSemiBoldDisabled = css` line-height: ${lineHeight20}; color: ${COLORS.medGreyHover}; cursor: not-allowed; -` +` \ No newline at end of file From df434ddaa28ebcc95ba918ad46f1caeace62a290 Mon Sep 17 00:00:00 2001 From: koji Date: Fri, 17 Nov 2023 11:17:33 -0500 Subject: [PATCH 4/9] fix linting errors --- .../DeckConfigurator/StagingAreaConfigFixture.tsx | 4 +--- .../DeckConfigurator/TrashBinConfigFixture.tsx | 4 +--- .../DeckConfigurator/WasteChuteConfigFixture.tsx | 2 +- .../src/hardware-sim/DeckConfigurator/constants.ts | 2 +- components/src/ui-style-constants/typography.ts | 10 +++++----- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx index 28f0b321041..80cecfd71d5 100644 --- a/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/StagingAreaConfigFixture.tsx @@ -45,9 +45,7 @@ export function StagingAreaConfigFixture( foreignObjectProps={{ flex: '1' }} > - + {STAGING_AREA_DISPLAY_NAME} {handleClickRemove != null ? ( diff --git a/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx index 9f1d968f288..c0c745e367e 100644 --- a/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/TrashBinConfigFixture.tsx @@ -51,9 +51,7 @@ export function TrashBinConfigFixture( foreignObjectProps={{ flex: '1' }} > - + {TRASH_BIN_DISPLAY_NAME} {handleClickRemove != null ? ( diff --git a/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx b/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx index 4d2491eed3d..5e974d7eb8a 100644 --- a/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/WasteChuteConfigFixture.tsx @@ -54,7 +54,7 @@ export function WasteChuteConfigFixture( foreignObjectProps={{ flex: '1' }} > - + {WASTE_CHUTE_DISPLAY_NAME} {handleClickRemove != null ? ( diff --git a/components/src/hardware-sim/DeckConfigurator/constants.ts b/components/src/hardware-sim/DeckConfigurator/constants.ts index 034d257f900..79f246274e3 100644 --- a/components/src/hardware-sim/DeckConfigurator/constants.ts +++ b/components/src/hardware-sim/DeckConfigurator/constants.ts @@ -3,4 +3,4 @@ export const SINGLE_SLOT_FIXTURE_WIDTH = 246.5 export const STAGING_AREA_FIXTURE_WIDTH = 318.5 export const STAGING_AREA_DISPLAY_NAME = 'Staging area' export const TRASH_BIN_DISPLAY_NAME = 'Trash bin' -export const WASTE_CHUTE_DISPLAY_NAME = 'Waste chute' \ No newline at end of file +export const WASTE_CHUTE_DISPLAY_NAME = 'Waste chute' diff --git a/components/src/ui-style-constants/typography.ts b/components/src/ui-style-constants/typography.ts index d480e7902dc..582e749c1da 100644 --- a/components/src/ui-style-constants/typography.ts +++ b/components/src/ui-style-constants/typography.ts @@ -217,10 +217,10 @@ export const smallBodyTextBold = css` font-weight: ${fontWeightBold}; ` -export const smallBodyTextSemiBold = css` -font-size: ${fontSize20}; -line-height: ${lineHeight24}; -font-weight: ${fontWeightSemiBold}; +export const smallBodyTextSemiBold = css` + font-size: ${fontSize20}; + line-height: ${lineHeight24}; + font-weight: ${fontWeightSemiBold}; ` export const smallBodyTextRegular = css` @@ -255,4 +255,4 @@ export const darkLinkLabelSemiBoldDisabled = css` line-height: ${lineHeight20}; color: ${COLORS.medGreyHover}; cursor: not-allowed; -` \ No newline at end of file +` From f15311b315aa15abe82ee4bdd6e868e11ffc0d50 Mon Sep 17 00:00:00 2001 From: koji Date: Fri, 17 Nov 2023 12:07:46 -0500 Subject: [PATCH 5/9] address a comment --- components/src/hardware-sim/DeckConfigurator/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/src/hardware-sim/DeckConfigurator/index.tsx b/components/src/hardware-sim/DeckConfigurator/index.tsx index bd483b5e3dc..a7d5d0b2c8a 100644 --- a/components/src/hardware-sim/DeckConfigurator/index.tsx +++ b/components/src/hardware-sim/DeckConfigurator/index.tsx @@ -7,6 +7,7 @@ import { STAGING_AREA_RIGHT_SLOT_FIXTURE, TRASH_BIN_ADAPTER_FIXTURE, WASTE_CHUTE_FIXTURES, + WASTE_CHUTE_ONLY_FIXTURES, WASTE_CHUTE_STAGING_AREA_FIXTURES, } from '@opentrons/shared-data' @@ -65,7 +66,9 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { ) const wasteChuteFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => - cutoutFixtureId != null && WASTE_CHUTE_FIXTURES.includes(cutoutFixtureId) + cutoutFixtureId != null && + (WASTE_CHUTE_FIXTURES.includes(cutoutFixtureId) || + WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId)) ) const wasteChuteStagingAreaFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => From 4737c60592999ebe1b4ed033044ae19b1e506e8f Mon Sep 17 00:00:00 2001 From: koji Date: Fri, 17 Nov 2023 14:41:53 -0500 Subject: [PATCH 6/9] Delete app.py used a wrong repo --- app.py | 104 --------------------------------------------------------- 1 file changed, 104 deletions(-) delete mode 100644 app.py diff --git a/app.py b/app.py deleted file mode 100644 index f01023bce2d..00000000000 --- a/app.py +++ /dev/null @@ -1,104 +0,0 @@ -import gradio as gr -import requests -import uuid -import os - -def string_to_binary(input_string): - binary_string = ''.join(format(ord(char), '08b') for char in input_string) - return binary_string - - -def upload_protocol(protocol_name): - robot_ip = "localhost" - # robot_url = "https://baxin-ot-analysis.hf.space" - endpoint = f"http://{robot_ip}:31950/protocols" - # protocol_name = generate_unique_name() - - protocol_file = open(protocol_name, "rb") - files = { - "files": (protocol_name, protocol_file), - } - - - headers = {"Opentrons-Version": "3"} - response = requests.post(endpoint, headers=headers, files=files) - response_data = response.json() - - protocol_file.close() - if os.path.exists(protocol_name): - # if the protocol file is existing, remove it - os.remove(protocol_name) - - if 'data' in response_data: - response_data = response.json() - protocol_id = response_data["data"]["id"] - analysis_result=response_data["data"]["analyses"] - analysis_id = response_data["data"]["analysisSummaries"][0]["id"] - analysis_status = response_data["data"]["analysisSummaries"][0]["status"] - print(protocol_id) - print(analysis_result) - print(analysis_id) - print(analysis_status) - return f"success\n protocol_id:{protocol_id}\n analysis_id:{analysis_id}" - else: - print("analysis error") - error_id = response_data["errors"][0]['id'] - error_code = response_data["errors"][0]["errorCode"] - error_detail = response_data["errors"][0]['detail'] - print(error_id) - print(error_code) - print(error_detail) - return f"{error_id}\n{error_code}\n{error_detail}" - -def generate_unique_name(): - unique_name = str(uuid.uuid4()) + ".py" - return unique_name - -def send_post_request(payload): - url = "https://baxin-simulator.hf.space/protocol" - protocol_name = generate_unique_name() - data = {"name": protocol_name, "content": payload} - headers = {"Content-Type": "application/json"} - - response = requests.post(url, json=data, headers=headers) - - if response.status_code != 200: - print("Error: " + response.text) - return "Error: " + response.text - - # Check the response before returning it - response_data = response.json() - if "error_message" in response_data: - print("Error in response:", response_data["error_message"]) - return response_data["error_message"] - elif "protocol_name" in response_data: - print("Protocol executed successfully. Run log:", response_data["run_log"]) - return response_data["run_log"] - else: - print("Unexpected response:", response_data) - return "Unexpected response" - - - - -def send_message(text, chatbot): - # Send POST request and get response -# response = send_post_request(text) -# binary_protocol = string_to_binary(text) - protocol_name = generate_unique_name() - with open(protocol_name, "w") as file: - file.write(text) - - response = upload_protocol(protocol_name) - # Update chatbot with response - chatbot.append(("opentrons analysis result", response)) - return chatbot - -with gr.Blocks() as app: - textbox = gr.Textbox() - send_button = gr.Button(value="Send") - chatbot = gr.Chatbot() - clear_button = gr.ClearButton([textbox, chatbot]) - send_button.click(send_message, [textbox, chatbot], [chatbot]) - -app.launch() From df69d83f3ce9829a8213d6180ba14368af9f67aa Mon Sep 17 00:00:00 2001 From: koji Date: Fri, 17 Nov 2023 15:41:30 -0500 Subject: [PATCH 7/9] Update index.tsx --- components/src/hardware-sim/DeckConfigurator/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/src/hardware-sim/DeckConfigurator/index.tsx b/components/src/hardware-sim/DeckConfigurator/index.tsx index a7d5d0b2c8a..716be3f9e96 100644 --- a/components/src/hardware-sim/DeckConfigurator/index.tsx +++ b/components/src/hardware-sim/DeckConfigurator/index.tsx @@ -67,8 +67,7 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { const wasteChuteFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => cutoutFixtureId != null && - (WASTE_CHUTE_FIXTURES.includes(cutoutFixtureId) || - WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId)) + WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId) ) const wasteChuteStagingAreaFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => From 44ec5572e9f988104ece6a886be2627f713ddda1 Mon Sep 17 00:00:00 2001 From: koji Date: Fri, 17 Nov 2023 15:46:46 -0500 Subject: [PATCH 8/9] fix contamination of wrong files --- app/src/assets/localization/en/device_details.json | 4 ++-- components/src/hardware-sim/DeckConfigurator/index.tsx | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/assets/localization/en/device_details.json b/app/src/assets/localization/en/device_details.json index 2a0c80d349c..466e52267a1 100644 --- a/app/src/assets/localization/en/device_details.json +++ b/app/src/assets/localization/en/device_details.json @@ -98,7 +98,7 @@ "mount": "{{side}} Mount", "na_speed": "Target: N/A", "na_temp": "Target: N/A", - "no_deck_fixtures": "No deck fixtures", + "no_deck_fixtures":"No deck fixtures", "no_protocol_runs": "No protocol runs yet!", "no_protocols_found": "No protocols found", "no_recent_runs_description": "After you run some protocols, they will appear here.", @@ -185,5 +185,5 @@ "waste_chute": "Waste chute", "welcome_modal_description": "A place to run protocols, manage your instruments, and view robot status.", "welcome_to_your_dashboard": "Welcome to your dashboard!", - "yes_update_now": "Yes, update now" + "yes_update_now": "Yes, update now", } diff --git a/components/src/hardware-sim/DeckConfigurator/index.tsx b/components/src/hardware-sim/DeckConfigurator/index.tsx index 716be3f9e96..9b6e782c4bf 100644 --- a/components/src/hardware-sim/DeckConfigurator/index.tsx +++ b/components/src/hardware-sim/DeckConfigurator/index.tsx @@ -6,7 +6,6 @@ import { SINGLE_SLOT_FIXTURES, STAGING_AREA_RIGHT_SLOT_FIXTURE, TRASH_BIN_ADAPTER_FIXTURE, - WASTE_CHUTE_FIXTURES, WASTE_CHUTE_ONLY_FIXTURES, WASTE_CHUTE_STAGING_AREA_FIXTURES, } from '@opentrons/shared-data' @@ -66,8 +65,7 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { ) const wasteChuteFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => - cutoutFixtureId != null && - WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId) + cutoutFixtureId != null && WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId) ) const wasteChuteStagingAreaFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => From 50483ae38def6980fc62010a378e79fb62457cb4 Mon Sep 17 00:00:00 2001 From: koji Date: Fri, 17 Nov 2023 15:56:33 -0500 Subject: [PATCH 9/9] fix linting errors --- app/src/assets/localization/en/device_details.json | 4 ++-- components/src/hardware-sim/DeckConfigurator/index.tsx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/assets/localization/en/device_details.json b/app/src/assets/localization/en/device_details.json index 466e52267a1..2a0c80d349c 100644 --- a/app/src/assets/localization/en/device_details.json +++ b/app/src/assets/localization/en/device_details.json @@ -98,7 +98,7 @@ "mount": "{{side}} Mount", "na_speed": "Target: N/A", "na_temp": "Target: N/A", - "no_deck_fixtures":"No deck fixtures", + "no_deck_fixtures": "No deck fixtures", "no_protocol_runs": "No protocol runs yet!", "no_protocols_found": "No protocols found", "no_recent_runs_description": "After you run some protocols, they will appear here.", @@ -185,5 +185,5 @@ "waste_chute": "Waste chute", "welcome_modal_description": "A place to run protocols, manage your instruments, and view robot status.", "welcome_to_your_dashboard": "Welcome to your dashboard!", - "yes_update_now": "Yes, update now", + "yes_update_now": "Yes, update now" } diff --git a/components/src/hardware-sim/DeckConfigurator/index.tsx b/components/src/hardware-sim/DeckConfigurator/index.tsx index 9b6e782c4bf..0e856e85d2a 100644 --- a/components/src/hardware-sim/DeckConfigurator/index.tsx +++ b/components/src/hardware-sim/DeckConfigurator/index.tsx @@ -65,7 +65,8 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { ) const wasteChuteFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => - cutoutFixtureId != null && WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId) + cutoutFixtureId != null && + WASTE_CHUTE_ONLY_FIXTURES.includes(cutoutFixtureId) ) const wasteChuteStagingAreaFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) =>