freemt
commited on
Commit
·
bdf7057
1
Parent(s):
96a6369
Update plt.savefig('img/df.png')
Browse files- app.py +28 -11
- img/df.png +0 -0
app.py
CHANGED
@@ -10,6 +10,10 @@ import subprocess as sp
|
|
10 |
from shlex import split
|
11 |
import pandas as pd
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# from textwrap import dedent
|
14 |
from inspect import cleandoc
|
15 |
import gradio as gr
|
@@ -18,6 +22,9 @@ from logzero import logger
|
|
18 |
|
19 |
from gradiobee.seg_text import seg_text
|
20 |
|
|
|
|
|
|
|
21 |
logzero.loglevel() # default to 10
|
22 |
|
23 |
|
@@ -56,17 +63,18 @@ def process(command):
|
|
56 |
|
57 |
# quick test altair altair-save tooltip
|
58 |
# from PIL import Image
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
62 |
|
63 |
df_ = pd.DataFrame(data={'x': [1, 2], 'y': [3, 4], "cos": [0.1, 0.5]})
|
64 |
-
chart_df = alt.Chart(df_).mark_circle(size=60).encode(
|
65 |
-
x='x',
|
66 |
-
y='y',
|
67 |
-
color='cos',
|
68 |
# tooltip=['x', 'y', 'cos', ]
|
69 |
-
)
|
70 |
# .interactive()
|
71 |
|
72 |
# save(chart_df, "chart_df.html")
|
@@ -80,8 +88,9 @@ def process(command):
|
|
80 |
# scatter_plot.save('simple_scatter_plot_with_altairchart.html')
|
81 |
# chart_df.save("chart_df.html") # does not work, constains js
|
82 |
# chart_df_html = Path("chart_df.html").read_text("utf")
|
83 |
-
|
84 |
-
|
|
|
85 |
|
86 |
# not is_command or not flag: text, do seg_text
|
87 |
_ = "\n\n".join(seg_text(command.strip()))
|
@@ -100,7 +109,15 @@ def process(command):
|
|
100 |
|
101 |
# return _, chart_df_html
|
102 |
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
|
106 |
iface = gr.Interface(
|
|
|
10 |
from shlex import split
|
11 |
import pandas as pd
|
12 |
|
13 |
+
import matplotlib
|
14 |
+
import matplotlib.pyplot as plt
|
15 |
+
import seaborn as sns
|
16 |
+
|
17 |
# from textwrap import dedent
|
18 |
from inspect import cleandoc
|
19 |
import gradio as gr
|
|
|
22 |
|
23 |
from gradiobee.seg_text import seg_text
|
24 |
|
25 |
+
matplotlib.use("Agg") # non-interactive for plt.savefig
|
26 |
+
sns.set()
|
27 |
+
sns.set_style("darkgrid")
|
28 |
logzero.loglevel() # default to 10
|
29 |
|
30 |
|
|
|
63 |
|
64 |
# quick test altair altair-save tooltip
|
65 |
# from PIL import Image
|
66 |
+
|
67 |
+
# import altair as alt
|
68 |
+
# from altair_saver import save
|
69 |
+
# alt.renderers.enable('altair_saver', fmts=['vega-lite', 'png'])
|
70 |
|
71 |
df_ = pd.DataFrame(data={'x': [1, 2], 'y': [3, 4], "cos": [0.1, 0.5]})
|
72 |
+
# chart_df = alt.Chart(df_).mark_circle(size=60).encode(
|
73 |
+
# x='x',
|
74 |
+
# y='y',
|
75 |
+
# color='cos',
|
76 |
# tooltip=['x', 'y', 'cos', ]
|
77 |
+
# )
|
78 |
# .interactive()
|
79 |
|
80 |
# save(chart_df, "chart_df.html")
|
|
|
88 |
# scatter_plot.save('simple_scatter_plot_with_altairchart.html')
|
89 |
# chart_df.save("chart_df.html") # does not work, constains js
|
90 |
# chart_df_html = Path("chart_df.html").read_text("utf")
|
91 |
+
|
92 |
+
# chart_df.save("chart_df.png") #
|
93 |
+
# chart_df_png = "chart_df.png"
|
94 |
|
95 |
# not is_command or not flag: text, do seg_text
|
96 |
_ = "\n\n".join(seg_text(command.strip()))
|
|
|
109 |
|
110 |
# return _, chart_df_html
|
111 |
|
112 |
+
plt.figure()
|
113 |
+
sns.scatterplot(data=df_, x='x', y='y')
|
114 |
+
Path("img").mkdir(exist_ok=True)
|
115 |
+
plt.savefig("img/df.png")
|
116 |
+
plt.close()
|
117 |
+
df_png = "img/df.png"
|
118 |
+
|
119 |
+
# return _, chart_df_png
|
120 |
+
return _, df_png
|
121 |
|
122 |
|
123 |
iface = gr.Interface(
|
img/df.png
ADDED
![]() |