Download app.py from Proton-Datalabs-dev/Chatgpt_plus_vs_api_cost: direct link, hf CLI and curl.
- Browser
- Download file 4.94 kB
-
https://huggingface.co/spaces/Proton-Datalabs-dev/Chatgpt_plus_vs_api_cost/resolve/main/app.py
- Command line
-
hf download hf://spaces/Proton-Datalabs-dev/Chatgpt_plus_vs_api_cost/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Proton-Datalabs-dev/Chatgpt_plus_vs_api_cost/resolve/main/app.py
4.94 kB
| import streamlit as st | |
| import numpy as np | |
| import plotly.graph_objects as go | |
| st.set_page_config() | |
| st.title('Cost Comparison Chatgpt Plus vs Custom-Chatgpt CoPilot') | |
| def note(): | |
| st.markdown(''' | |
| # ChatGPT plans | |
| - Plus - $20/month with 320 and 640 msgs per day cap for GPT-4 and GPT-4o models resp | |
| - Teams - $30/month with 800 and 1600 msgs per day cap for GPT-4 and GPT-4o models resp (minimum 2 users) | |
| [link](https://openai.com/chatgpt/pricing) | |
| # API plans | |
| - GPT-4o: \\$5/1Million input tokens, $15/1Million output tokens | |
| - GPT4: \\$30/1Million input tokens, $60/1Million output tokens | |
| [link](https://openai.com/api/pricing) | |
| # Assumptions | |
| - 1 token = 0.75 words (1.33 tokens ≈ 1 word) | |
| - For ChatGPT API plans, we consider 1 input prompt = 250 words and same word count for output messages | |
| ''') | |
| # if st.button("Show Assumptions"): | |
| # note() | |
| with st.sidebar: | |
| st.title("Model Parameters") | |
| max_months = st.select_slider("No. of months to show on plot (x-axis)", | |
| options=np.arange(0, 37, 1, dtype=int), value=13) | |
| no_of_users = st.select_slider("No. of users", | |
| options=np.arange(10, 501, 1, dtype=int), value=30) | |
| st.subheader("One-Time Development Cost (Custom App)", divider="gray") | |
| development_cost = st.select_slider("Development Cost for Custom App ($)", | |
| options=np.arange(3000, 20001, 100, dtype=int), value=3000) | |
| st.subheader("Token Usage", divider="gray") | |
| st.markdown(""" | |
| **Note:** | |
| - 1 token = 0.75 words | |
| - 1.33 tokens $\\approx$ 1 word | |
| """, unsafe_allow_html=True) | |
| input_tokens_per_month = st.slider("Input Tokens per user (Monthly)", | |
| min_value=10000, max_value=500000, step=10000, value=85000) | |
| output_tokens_per_month = st.slider("Output Tokens per user (Monthly)", | |
| min_value=10000, max_value=500000, step=10000, value=85000) | |
| # Fixed parameters | |
| plan_limits = {"Plus": {"GPT-4o": 640, "GPT4": 320, "price": 20}, # 40 messages/3hrs | |
| "Team": {"GPT-4o": 1600, "GPT4": 800, "price": 30}} # 100 messages/3hrs, minimum 2 users price 25 pm if billed annually | |
| api_price = {"GPT-4o": {"input": 0.0100, "output": 0.0300}, "GPT4": {"input": 0.0100, "output": 0.0300}} #usd per 1K tokens | |
| # Timeline | |
| x = np.arange(0, max_months, dtype=int) # in months timeline | |
| # Accumulated cost for ChatGPT-4o API | |
| api_price_per_month = x * (api_price["GPT4"]["input"] * input_tokens_per_month *0.001 + | |
| api_price["GPT4"]["output"] * output_tokens_per_month*0.001) * no_of_users | |
| # Accumulated cost for ChatGPT Team | |
| team_price_per_month = x * no_of_users * plan_limits["Plus"]["price"] | |
| # # Calculate breakeven month | |
| savings_per_month=(team_price_per_month-api_price_per_month)/x | |
| if savings_per_month[1] > 0: | |
| breakeven_month = development_cost / savings_per_month[1] | |
| else: | |
| breakeven_month = None | |
| # Plotting | |
| fig = go.Figure() | |
| fig.add_trace(go.Scatter(x=x, y=team_price_per_month, name='ChatGPT Plus', fillcolor="red", line=dict(color='red'))) | |
| fig.add_trace(go.Scatter(x=x, y=api_price_per_month + development_cost, name='Custom-Chatgpt', fillcolor="blue", line=dict(color='blue'))) | |
| fig.update_layout(title="Accumulated Monthly Costs Over Time", | |
| xaxis_title="Time in Months", | |
| yaxis_title="Accumulated Cost in $") | |
| # Add breakeven annotation if applicable | |
| if breakeven_month is not None and breakeven_month < max_months: | |
| fig.add_vline(x=breakeven_month, line_dash="dash", line_color="black") | |
| fig.add_annotation(x=breakeven_month, y=api_price_per_month[int(breakeven_month)] + development_cost, | |
| text=f"Breakeven at {breakeven_month:.1f} months", | |
| showarrow=True, arrowhead=1) | |
| st.plotly_chart(fig) | |
| # Description | |
| st.info(''' | |
| This plot compares the accumulated costs of two options over time: ChatGPT Teams and GPT-4o API with a Custom Application. | |
| 1. **ChatGPT Teams**: A fixed cost per user with no upfront development costs. | |
| 2. **GPT-4o API with Custom Application**: Includes a one-time development cost and usage-based charges for input and output tokens. | |
| #### Key Insights: | |
| - The black dashed line indicates the **breakeven point**, where the total cost of the custom application becomes equal to or less than the cost of ChatGPT Teams. | |
| - Beyond this point, the custom application provides **cost savings** compared to ChatGPT Teams. | |
| Use the sliders to adjust parameters like the number of users and the one-time development cost to see how they affect the breakeven point and accumulated costs. | |
| ''') | |