Spaces:
Runtime error
Runtime error
Commit ·
d04c4ef
1
Parent(s): 412e10d
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
# Calculate angles
|
| 13 |
-
angles = [2 * np.pi * i / num_params for i in range(num_params)]
|
| 14 |
-
angles += angles[:1] # Complete the circle
|
| 15 |
-
|
| 16 |
-
# Create a Gradio plot for the radar chart
|
| 17 |
-
radar_chart = gr.Plot()
|
| 18 |
-
radar_chart.plot_type = "radar"
|
| 19 |
-
radar_chart.labels = params_list
|
| 20 |
-
radar_chart.values = values
|
| 21 |
-
radar_chart.color = "blue" # Adjust the color as needed
|
| 22 |
-
radar_chart.title = chart_title
|
| 23 |
-
|
| 24 |
-
return radar_chart
|
| 25 |
-
|
| 26 |
-
# Create a Gradio interface
|
| 27 |
-
iface = gr.Interface(
|
| 28 |
-
fn=create_radar_chart,
|
| 29 |
-
inputs=[
|
| 30 |
-
gr.Textbox(label="Parameters (Comma-separated)", placeholder="Parameter1,Parameter2,Parameter3"),
|
| 31 |
-
gr.Textbox(label="Chart Title", value="Radar Chart"),
|
| 32 |
-
],
|
| 33 |
-
outputs=gr.Plot(label="Radar Chart Display")
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
# Launch the Gradio interface
|
| 37 |
if __name__ == "__main__":
|
| 38 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import altair as alt
|
| 3 |
+
import pandas as pd
|
| 4 |
|
| 5 |
+
def make_plot(plot_type):
|
| 6 |
+
if plot_type == "radial":
|
| 7 |
+
source = pd.DataFrame({
|
| 8 |
+
"values": [12, 23, 47, 6, 52, 19]
|
| 9 |
+
})
|
| 10 |
+
base = alt.Chart(source).encode(
|
| 11 |
+
theta=alt.Theta("values:Q", stack=True),
|
| 12 |
+
radius=alt.Radius("values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)),
|
| 13 |
+
color="values:N",
|
| 14 |
+
)
|
| 15 |
+
c1 = base.mark_arc(innerRadius=20, stroke="#fff")
|
| 16 |
+
c2 = base.mark_text(radiusOffset=10).encode(text="values:Q")
|
| 17 |
+
return c1 + c2
|
| 18 |
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
button = gr.Radio(label="Plot type", choices=["radial"], value="radial")
|
| 21 |
+
plot = gr.Plot(label="Plot")
|
| 22 |
+
button.change(make_plot, inputs=button, outputs=[plot])
|
| 23 |
+
demo.load(make_plot, inputs=[button], outputs=[plot])
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|