Spaces:
Build error
Build error
Update app_v3.py
Browse files
app_v3.py
CHANGED
|
@@ -147,45 +147,3 @@ def run_pipeline(file, scenario):
|
|
| 147 |
if file is None:
|
| 148 |
_err("No file uploaded")
|
| 149 |
df_hist = load_csv(file); fc, errs = baseline_forecast(df_hist)
|
| 150 |
-
drivers_base = {"rev_growth_pct":0.0, "gm_bps":0, "opex_infl_pct":0.0, "fx_pct":0.0, "dso":60, "dpo":45, "dio":60, "dep":0.05, "interest":0.01, "tax_rate":0.25}
|
| 151 |
-
drivers_best = {**drivers_base, "rev_growth_pct":0.10, "gm_bps":200, "opex_infl_pct":-0.05, "fx_pct":0.02}
|
| 152 |
-
drivers_worst = {**drivers_base, "rev_growth_pct":-0.10, "gm_bps":-200, "opex_infl_pct":0.10, "fx_pct":-0.03}
|
| 153 |
-
|
| 154 |
-
if scenario == "Baseline":
|
| 155 |
-
out = apply_scenario(fc, drivers_base)
|
| 156 |
-
plot_img = Image.open(plot_series(out, "Baseline"))
|
| 157 |
-
meta = {"audit": audit_row(drivers_base, "Baseline"), "baseline_warnings": errs or None}
|
| 158 |
-
return plot_img, out.to_csv(index=False).encode(), json.dumps(meta, indent=2)
|
| 159 |
-
|
| 160 |
-
base_df = apply_scenario(fc, drivers_base)
|
| 161 |
-
best_df = apply_scenario(fc, drivers_best)
|
| 162 |
-
worst_df = apply_scenario(fc, drivers_worst)
|
| 163 |
-
|
| 164 |
-
ok_b = all(check_bounds(d)[0] for d in [drivers_base, drivers_best, drivers_worst])
|
| 165 |
-
ok_cons = all(check_conservation(d) for d in [base_df, best_df, worst_df])
|
| 166 |
-
ok_mono, eb, ca = check_monotonicity(base_df, worst_df, best_df)
|
| 167 |
-
status = {"bounds": ok_b, "conservation": ok_cons, "monotonicity": ok_mono, "baseline_warnings": errs or None}
|
| 168 |
-
|
| 169 |
-
out = base_df if scenario == "Base" else best_df if scenario == "Best" else worst_df
|
| 170 |
-
plot_img = Image.open(plot_series(out, f"Scenario: {scenario}"))
|
| 171 |
-
meta = {"scenario": scenario, "totals": {"EBITDA": eb, "Cash": ca}, "status": status}
|
| 172 |
-
return plot_img, out.to_csv(index=False).encode(), json.dumps(meta, indent=2)
|
| 173 |
-
|
| 174 |
-
with gr.Blocks(title="Corporate Forecast Agent — Detailed Errors") as demo:
|
| 175 |
-
gr.Markdown("## Corporate Forecast Agent — Best / Base / Worst")
|
| 176 |
-
gr.Markdown("Upload CSV with columns: date,revenue,cogs,opex (monthly). Errors now include detailed JSON.")
|
| 177 |
-
file = gr.File(file_types=[".csv"], label="Upload CSV")
|
| 178 |
-
scenario = gr.Radio(["Baseline","Best","Base","Worst"], value="Baseline", label="Scenario")
|
| 179 |
-
btn = gr.Button("Run")
|
| 180 |
-
img = gr.Image(type="pil", label="Plots")
|
| 181 |
-
dl = gr.File(label="Download forecast.csv")
|
| 182 |
-
meta = gr.JSON(label="Validation & Diagnostics")
|
| 183 |
-
def _run(file_obj, scen):
|
| 184 |
-
plot_img, csv_bytes, meta_json = run_pipeline(file_obj.name if file_obj else None, scen)
|
| 185 |
-
return plot_img, ("forecast.csv", csv_bytes), meta_json
|
| 186 |
-
btn.click(_run, inputs=[file, scenario], outputs=[img, dl, meta])
|
| 187 |
-
|
| 188 |
-
demo.queue()
|
| 189 |
-
if __name__ == "__main__":
|
| 190 |
-
demo.launch()
|
| 191 |
-
|
|
|
|
| 147 |
if file is None:
|
| 148 |
_err("No file uploaded")
|
| 149 |
df_hist = load_csv(file); fc, errs = baseline_forecast(df_hist)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|