Spaces:
Runtime error
Runtime error
Download app.py from Lifesightio/Marketing_Mix_Modeling: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/spaces/Lifesightio/Marketing_Mix_Modeling/resolve/main/app.py
- Command line
-
hf download hf://spaces/Lifesightio/Marketing_Mix_Modeling/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Lifesightio/Marketing_Mix_Modeling/resolve/main/app.py
2 kB
| import gradio as gr | |
| def calculate(treatment, control, treated_n, control_n, spend): | |
| if min(treatment, control, spend) < 0: | |
| return "Revenue and spend cannot be negative." | |
| if treated_n <= 0 or control_n <= 0: | |
| return "Group sizes must be greater than zero." | |
| treated_avg = treatment / treated_n | |
| control_avg = control / control_n | |
| incremental = (treated_avg - control_avg) * treated_n | |
| baseline = control_avg * treated_n | |
| lift = (incremental / baseline * 100) if baseline > 0 else None | |
| iroas = (incremental / spend) if spend > 0 else None | |
| return f""" | |
| ## Your Incrementality Results | |
| **Estimated incremental revenue:** ${incremental:,.2f} | |
| **Estimated revenue lift:** {f'{lift:.2f}%' if lift is not None else 'N/A'} | |
| **Estimated incremental ROAS:** {f'{iroas:.2f}x' if iroas is not None else 'N/A'} | |
| --- | |
| *Illustrative calculation. A causal interpretation requires | |
| comparable groups, a valid experimental design, and | |
| appropriate statistical uncertainty analysis.* | |
| """ | |
| with gr.Blocks(title="Lifesight Incrementality Calculator") as demo: | |
| gr.Markdown( | |
| "# Lifesight | Marketing Incrementality Calculator\n" | |
| "Estimate incremental revenue and iROAS using " | |
| "treatment and control group results." | |
| ) | |
| with gr.Row(): | |
| treatment = gr.Number( | |
| label="Treatment Revenue ($)", value=120000 | |
| ) | |
| control = gr.Number( | |
| label="Control Revenue ($)", value=100000 | |
| ) | |
| with gr.Row(): | |
| treated_n = gr.Number( | |
| label="Treatment Group Size", value=1000 | |
| ) | |
| control_n = gr.Number( | |
| label="Control Group Size", value=1000 | |
| ) | |
| spend = gr.Number(label="Campaign Spend ($)", value=10000) | |
| button = gr.Button("Calculate Incrementality", variant="primary") | |
| result = gr.Markdown() | |
| button.click( | |
| fn=calculate, | |
| inputs=[treatment, control, treated_n, control_n, spend], | |
| outputs=result | |
| ) | |
| demo.launch() | |