dindizz's picture
Update app.py
736ca5d verified
import gradio as gr
def calculate_page_views(revenue, cpm):
try:
# Convert inputs to float
revenue = float(revenue)
cpm = float(cpm)
# Calculate total annual page views
annual_page_views = (revenue * 1000) / cpm # Revenue (₹) * 1000 / CPM (₹)
annual_page_views_millions = annual_page_views / 1_000_000 # Convert to millions
# Calculate monthly and daily page views
monthly_page_views = annual_page_views / 12
monthly_page_views_millions = monthly_page_views / 1_000_000 # Convert to millions
daily_page_views = annual_page_views / 365
daily_page_views_millions = daily_page_views / 1_000_000 # Convert to millions
# Return results
return (f"Annual Page Views: {annual_page_views:.0f} ({annual_page_views_millions:.2f}M)",
f"Monthly Page Views: {monthly_page_views:.0f} ({monthly_page_views_millions:.2f}M)",
f"Daily Page Views: {daily_page_views:.0f} ({daily_page_views_millions:.2f}M)")
except Exception as e:
return f"Error: {str(e)}", "", ""
# Gradio Interface
with gr.Blocks() as forecast_calculator:
gr.Markdown("## Programmatic Pageviews Forecast Calculator (in ₹)")
gr.Markdown(
"Enter the **Revenue** (₹) and **CPM** (₹), and the calculator will display the page views required annually, monthly, and daily."
)
with gr.Row():
revenue_input = gr.Textbox(label="Revenue (in ₹)", placeholder="Enter total revenue (e.g., 5000000)")
cpm_input = gr.Textbox(label="CPM (in ₹)", placeholder="Enter CPM (e.g., 50)")
calculate_button = gr.Button("Calculate Page Views")
with gr.Row():
annual_output = gr.Textbox(label="Annual Page Views")
monthly_output = gr.Textbox(label="Monthly Page Views")
daily_output = gr.Textbox(label="Daily Page Views")
calculate_button.click(
calculate_page_views,
inputs=[revenue_input, cpm_input],
outputs=[annual_output, monthly_output, daily_output]
)
forecast_calculator.launch()