rayochoajr commited on
Commit
5053d32
·
1 Parent(s): 9a3a908

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -50
app.py CHANGED
@@ -1,56 +1,15 @@
1
  import gradio as gr
2
- import plotly.express as px
3
- import pandas as pd
4
 
5
- # Prepare some sample data
6
- df = pd.DataFrame({
7
- "x": [1, 2, 3, 4],
8
- "y": [2, 4, 6, 8],
9
- "z": [3, 6, 9, 12],
10
- "color": ["red", "green", "blue", "orange"]
11
- })
12
 
13
- # Define a function that takes a plot object as input and returns some values for output sections
14
- def update_output(plot):
15
- # Get the data from the plot object
16
- data = plot.data[0]
17
- # Calculate some statistics
18
- mean_x = data.x.mean()
19
- mean_y = data.y.mean()
20
- mean_z = data.z.mean()
21
- # Get the selected point index
22
- point_index = data.selectedpoints[0] if data.selectedpoints else None
23
- # Get the point color
24
- point_color = data.marker.color[point_index] if point_index is not None else None
25
- # Return the values for output sections
26
- return mean_x, mean_y, mean_z, point_index, point_color
27
 
28
- # Define some output sections as gradio components
29
- mean_x_box = gr.Textbox(label="Mean x")
30
- mean_y_box = gr.Textbox(label="Mean y")
31
- mean_z_box = gr.Textbox(label="Mean z")
32
- point_index_label = gr.Label(label="Selected point index")
33
- point_color_label = gr.Label(label="Selected point color")
34
 
35
- # Create a plot object using plotly
36
- plot = px.scatter_3d(df, x="x", y="y", z="z", color="color")
37
-
38
- # Create a gradio.Plot widget as an input component
39
- plot_input = gr.Plot(label="Plot", value=plot)
40
-
41
- # Create a gradio.Interface object
42
- iface = gr.Interface(
43
- fn=update_output,
44
- inputs=plot_input,
45
- outputs=[mean_x_box, mean_y_box, mean_z_box, point_index_label, point_color_label],
46
- layout="vertical",
47
- theme="huggingface",
48
- title="Gradio Plot Example",
49
- description="This is an example of using a gradio.Plot widget as an input component and updating some output sections based on user interaction."
50
- )
51
-
52
- # Add an event trigger to the input component
53
- plot_input.change(update_output)
54
-
55
- # Launch the interface
56
  iface.launch()
 
1
  import gradio as gr
2
+ from gradio.components import Ace
 
3
 
4
+ # Define a function that takes a code string as input and returns it as output
5
+ def echo_code(code):
6
+ return code
 
 
 
 
7
 
8
+ # Create an Ace component with Python mode and Monokai theme
9
+ ace = Ace(mode="python", theme="monokai")
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ # Create a gradio app with the Ace component as both input and output
12
+ iface = gr.Interface(fn=echo_code, inputs=ace, outputs=ace)
 
 
 
 
13
 
14
+ # Launch the app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  iface.launch()