hand_configuration_distortion / example_gradio_app_doc_copy.py
jmartinezot's picture
Showing goal and tentative hand
fd843fb
import altair as alt
import gradio as gr
import numpy as np
import pandas as pd
from vega_datasets import data
import plotly.graph_objects as go
def plot_random_points_3d(num_points):
# Generate random points in 3D space
np.random.seed(42) # Setting a seed for reproducibility
x = np.random.randn(num_points)
y = np.random.randn(num_points)
z = np.random.randn(num_points)
# Create a scatter plot
fig = go.Figure(data=go.Scatter3d(
x=x,
y=y,
z=z,
mode='markers',
marker=dict(
size=5,
color='blue',
opacity=0.8
)
))
# Set axes labels and title
fig.update_layout(
scene=dict(
xaxis=dict(title='X'),
yaxis=dict(title='Y'),
zaxis=dict(title='Z')
),
title='3D Random Points'
)
# Return the figure
return fig
def make_plot(plot_type):
if plot_type == "multiline":
source = data.stocks()
highlight = alt.selection(type='single', on='mouseover',
fields=['symbol'], nearest=True)
base = alt.Chart(source).encode(
x='date:T',
y='price:Q',
color='symbol:N'
)
points = base.mark_circle().encode(
opacity=alt.value(0)
).add_selection(
highlight
).properties(
width=600
)
lines = base.mark_line().encode(
size=alt.condition(~highlight, alt.value(1), alt.value(3))
)
return points + lines
elif plot_type == "3Dplot":
return plot_random_points_3d(100)
with gr.Blocks() as demo:
button = gr.Radio(label="Plot type",
choices=["multiline", "3Dplot"], value='3Dplot')
plot = gr.Plot(label="Plot")
button.change(make_plot, inputs=button, outputs=[plot])
demo.load(make_plot, inputs=[button], outputs=[plot])
if __name__ == "__main__":
demo.launch()