Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Nov 17, 2023
1 parent de63008 commit 68dad5a
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 26 deletions.
104 changes: 104 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export function StagingAreaConfigFixture(
>
<Flex css={STAGING_AREA_CONFIG_STYLE}>
<Text
fontSize={TYPOGRAPHY.fontSize20}
lineHeight={TYPOGRAPHY.lineHeight24}
fontWeight={TYPOGRAPHY.fontWeightSemiBold}
css={TYPOGRAPHY.smallBodyTextSemiBold }
>
{STAGING_AREA_DISPLAY_NAME}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export function TrashBinConfigFixture(
>
<Flex css={TRASH_BIN_CONFIG_STYLE}>
<Text
fontSize={TYPOGRAPHY.fontSize20}
lineHeight={TYPOGRAPHY.lineHeight24}
fontWeight={TYPOGRAPHY.fontWeightSemiBold}
css={TYPOGRAPHY.smallBodyTextSemiBold }
>
{TRASH_BIN_DISPLAY_NAME}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function WasteChuteConfigFixture(
foreignObjectProps={{ flex: '1' }}
>
<Flex css={WASTE_CHUTE_CONFIG_STYLE}>
<Text css={TYPOGRAPHY.bodyTextSemiBold}>
<Text css={TYPOGRAPHY.smallBodyTextSemiBold }>
{WASTE_CHUTE_DISPLAY_NAME}
</Text>
{handleClickRemove != null ? (
Expand Down
19 changes: 1 addition & 18 deletions components/src/hardware-sim/DeckConfigurator/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 8 additions & 1 deletion components/src/ui-style-constants/typography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -232,6 +238,7 @@ export const darkLinkH4SemiBold = css`
color: ${COLORS.darkBlackEnabled};
}
`

export const darkLinkLabelSemiBold = css`
font-size: ${fontSizeLabel};
font-weight: ${fontWeightSemiBold};
Expand All @@ -248,4 +255,4 @@ export const darkLinkLabelSemiBoldDisabled = css`
line-height: ${lineHeight20};
color: ${COLORS.medGreyHover};
cursor: not-allowed;
`
`

0 comments on commit 68dad5a

Please sign in to comment.