cloud450 commited on
Commit
04c7d16
·
verified ·
1 Parent(s): e5080b9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -15,6 +15,8 @@ import matplotlib.gridspec as gridspec
15
  import seaborn as sns
16
  import io
17
  import gradio as gr
 
 
18
 
19
  from statsmodels.tsa.stattools import adfuller
20
  from statsmodels.tsa.arima.model import ARIMA
@@ -168,13 +170,13 @@ def detect_anomalies(actual, fitted, k=2.5):
168
  # ─────────────────────────────────────────────
169
  # PLOT HELPERS
170
  # ─────────────────────────────────────────────
 
171
  def _fig_to_pil(fig):
172
- """Convert matplotlib figure to PIL Image bytes for Gradio."""
173
- buf = io.BytesIO()
174
- fig.savefig(buf, format="png", dpi=130, bbox_inches="tight",
175
  facecolor=fig.get_facecolor())
176
- buf.seek(0)
177
- return buf
178
 
179
 
180
  def plot_overview(df):
 
15
  import seaborn as sns
16
  import io
17
  import gradio as gr
18
+ import tempfile
19
+
20
 
21
  from statsmodels.tsa.stattools import adfuller
22
  from statsmodels.tsa.arima.model import ARIMA
 
170
  # ─────────────────────────────────────────────
171
  # PLOT HELPERS
172
  # ─────────────────────────────────────────────
173
+
174
  def _fig_to_pil(fig):
175
+ """Save matplotlib figure to temp file and return filepath (Gradio-compatible)."""
176
+ tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
177
+ fig.savefig(tmp.name, dpi=130, bbox_inches="tight",
178
  facecolor=fig.get_facecolor())
179
+ return tmp.name
 
180
 
181
 
182
  def plot_overview(df):