gursi26's picture
added all
bd88e0f
raw
history blame
3.26 kB
import gradio as gr
import time
import random
def handle_request(selected_command, angle1=0.0, angle2=0.0, angle3=0.0, angle4=0.0, angle5=0.0, angle6=0.0,
coord1=0.0, coord2=0.0, coord3=0.0, coord4=0.0, coord5=0.0, coord6=0.0,
gripper_value=0.0, speed_angles=0.0, speed_coords=0.0, speed_gripper=0.0):
time.sleep(random.randint(1, 5))
return f"Command: {selected_command}, Params: {locals()}"
options = [
"query/angles", "query/coords", "query/camera", "query/gripper",
"control/angles", "control/coords", "control/gripper"
]
with gr.Blocks() as app:
gr.Markdown("# MyCobot 280pi MQTT Control demo")
gr.Markdown("This is a public demo of the MyCobot 280pi...")
selected_command = gr.Dropdown(choices=options, label="Select command")
with gr.Group(visible=False) as query_angles_group:
pass
with gr.Group(visible=False) as query_coords_group:
pass
with gr.Group(visible=False) as query_camera_group:
pass
with gr.Group(visible=False) as query_gripper_group:
pass
with gr.Group(visible=False) as control_angles_group:
angle1 = gr.Number(value=0.0, label="Angle 1", step=5.0)
angle2 = gr.Number(value=0.0, label="Angle 2", step=5.0)
angle3 = gr.Number(value=0.0, label="Angle 3", step=5.0)
angle4 = gr.Number(value=0.0, label="Angle 4", step=5.0)
angle5 = gr.Number(value=0.0, label="Angle 5", step=5.0)
angle6 = gr.Number(value=0.0, label="Angle 6", step=5.0)
speed_angles = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Speed")
with gr.Group(visible=False) as control_coords_group:
coord1 = gr.Number(value=0.0, label="X coordinate", step=5.0)
coord2 = gr.Number(value=0.0, label="Y coordinate", step=5.0)
coord3 = gr.Number(value=0.0, label="Z coordinate", step=5.0)
coord4 = gr.Number(value=0.0, label="Rotation X", step=5.0)
coord5 = gr.Number(value=0.0, label="Rotation Y", step=5.0)
coord6 = gr.Number(value=0.0, label="Rotation Z", step=5.0)
speed_coords = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Speed")
with gr.Group(visible=False) as control_gripper_group:
gripper_value = gr.Slider(minimum=0.0, maximum=100.0, step=1.0, label="Gripper value")
speed_gripper = gr.Slider(value=50.0, minimum=0.0, maximum=100.0, step=1.0, label="Speed")
def toggle_visibility(command):
return (
gr.update(visible=command == "query/angles"),
gr.update(visible=command == "query/coords"),
gr.update(visible=command == "query/camera"),
gr.update(visible=command == "query/gripper"),
gr.update(visible=command == "control/angles"),
gr.update(visible=command == "control/coords"),
gr.update(visible=command == "control/gripper")
)
selected_command.change(
toggle_visibility,
selected_command,
[
query_angles_group, query_coords_group, query_camera_group, query_gripper_group,
control_angles_group, control_coords_group, control_gripper_group
]
)
submit_button = gr.Button("Send Command")
output_text = gr.Textbox()
submit_button.click(
handle_request,
inputs=[selected_command, angle1, angle2, angle3, angle4, angle5, angle6,
coord1, coord2, coord3, coord4, coord5, coord6, gripper_value, speed_angles,
speed_coords, speed_gripper],
outputs=output_text
)
app.launch(server_port=9000)