Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
# import time
|
| 5 |
+
|
| 6 |
+
st.set_page_config()
|
| 7 |
+
st.title('RoI on Openai Chatgpt vs API plans') #
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@st.dialog("Assumptions")
|
| 11 |
+
def note():
|
| 12 |
+
st.markdown('''
|
| 13 |
+
# ChatGPT plans
|
| 14 |
+
- Plus - $20/month with 320 and 640 msgs per day cap for GPT4 and GPT-4o models resp
|
| 15 |
+
- Teams - $30/month with 800 and 1600 msgs per day cap for GPT4 and GPT-4o models resp (minimum 2 users)
|
| 16 |
+
[link](https://openai.com/chatgpt/pricing)
|
| 17 |
+
|
| 18 |
+
# API plans
|
| 19 |
+
- GPT-4o: \\$5/1Million input tokens, $15/1Million output tokens
|
| 20 |
+
- GPT4: \\$30/1Million input tokens, $60/1Million output tokens
|
| 21 |
+
[link](https://openai.com/api/pricing)
|
| 22 |
+
|
| 23 |
+
# Assumptions
|
| 24 |
+
- 1 token = 0.75 words (1.33 token $\\approx$ 1 word)
|
| 25 |
+
- For Chatgpt API plans, we consider 1 input prompt = 250 words and same word count for output messages
|
| 26 |
+
|
| 27 |
+
''')
|
| 28 |
+
|
| 29 |
+
# st.button("Note")
|
| 30 |
+
if st.button("Show Assumptions"):
|
| 31 |
+
note()
|
| 32 |
+
|
| 33 |
+
with st.sidebar:
|
| 34 |
+
st.title("Model Parameters")
|
| 35 |
+
max_months = st.select_slider("No. of months to show on plot (x-axis)",
|
| 36 |
+
options = np.arange(0, 37, 1, dtype=int), value=13)
|
| 37 |
+
|
| 38 |
+
no_of_users = st.select_slider("No. of users",
|
| 39 |
+
options = np.arange(0, 100, 1, dtype=int), value=2)
|
| 40 |
+
|
| 41 |
+
st.subheader("Rest params app. for API plans only", divider="gray")
|
| 42 |
+
|
| 43 |
+
daily_no_of_prompts = st.select_slider("No. of prompts expected per day per user",
|
| 44 |
+
options = np.arange(0, 1520, 20, dtype=int), value=100)
|
| 45 |
+
|
| 46 |
+
input_prompts_word_cnt = st.select_slider("No. of words given as prompt to llm",
|
| 47 |
+
options = np.arange(0, 1050, 50, dtype=int), value=200)
|
| 48 |
+
|
| 49 |
+
output_prompts_word_cnt = st.select_slider("No. of words in the output response from llm",
|
| 50 |
+
options = np.arange(0, 1050, 50, dtype=int), value=200)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# fixed
|
| 54 |
+
plan_limits = {"Plus": {"GPT-4o": 640, "GPT4": 320, "price": 20}, # 40 messages/3hrs
|
| 55 |
+
"Team": {"GPT-4o": 1600, "GPT4": 800, "price": 30}} # 100 messages/3hrs, minimum 2 users price 25 pm if billed annually
|
| 56 |
+
|
| 57 |
+
api_limits = {"GPT-4o": {"input": 5, "output": 15}, "GPT4": {"input": 30, "output": 60}} #usd per 1M tokens
|
| 58 |
+
|
| 59 |
+
# assumptions
|
| 60 |
+
token_to_word_ratio = 0.75
|
| 61 |
+
word_to_token_ratio = 1/token_to_word_ratio
|
| 62 |
+
|
| 63 |
+
x = np.arange(0, max_months, dtype=int) # in months timeline
|
| 64 |
+
|
| 65 |
+
api_price_per_month = {k: x*(v["input"] * daily_no_of_prompts * input_prompts_word_cnt * word_to_token_ratio +
|
| 66 |
+
v["output"] * daily_no_of_prompts * output_prompts_word_cnt * word_to_token_ratio)*30/1_000_000 for k, v in api_limits.items()}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
fig = go.Figure()
|
| 70 |
+
fig.add_trace(go.Scatter(x=x, y=api_price_per_month['GPT4'], name='GPT-4 API', fillcolor="darkkhaki"))
|
| 71 |
+
fig.add_trace(go.Scatter(x=x, y=api_price_per_month['GPT-4o'], name='GPT-4o API', fillcolor="darkgreen"))
|
| 72 |
+
fig.add_trace(go.Scatter(x=x, y=x*no_of_users*plan_limits["Team"]['price'], name='Chatgpt Team', fillcolor="firebrick"))
|
| 73 |
+
fig.add_trace(go.Scatter(x=x, y=x*no_of_users*plan_limits["Plus"]['price'], name='Chatgpt Plus', fillcolor="dodgerblue"))
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
fig.update_layout(title="Accumulated monthly costs over time",
|
| 77 |
+
xaxis_title="time in months",
|
| 78 |
+
yaxis_title="accu. cost in $")
|
| 79 |
+
|
| 80 |
+
st.plotly_chart(fig)
|