azizalto commited on
Commit
6bac693
·
1 Parent(s): 4eb3d76

Update app.py

Browse files

- add page icon
- remove submit button and automatically calculate cost once the the prompt is entered in the text area

Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  import pandas as pd
3
  from transformers import GPT2Tokenizer
4
 
 
 
5
  # Load the tokenizer
6
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
7
 
@@ -36,20 +38,23 @@ def calculate_cost(model, input_tokens, output_tokens):
36
 
37
  # Streamlit App
38
  st.title("GPT/LLM Usage Cost Estimator")
 
39
 
40
  # User input
41
- user_input = st.text_area("Enter your prompt")
42
- estimated_output_tokens = st.number_input("Estimated number of output tokens", min_value=0, value=50)
43
  selected_model = st.selectbox("Select the model", list(rate_prices.keys()))
44
 
45
- if st.button("Calculate Cost"):
 
46
  input_tokens = count_tokens(user_input)
47
  total_cost = calculate_cost(selected_model, input_tokens, estimated_output_tokens)
48
 
 
49
  # Create a DataFrame for displaying results
50
  results_df = pd.DataFrame({
51
  "Detail": ["Number of Input Tokens", "Estimated Number of Output Tokens", "Estimated Total Cost"],
52
- "Value": [input_tokens, estimated_output_tokens, f"${total_cost:.2f}"]
53
  })
54
 
55
  # Display the results in a table
@@ -61,5 +66,5 @@ st.markdown("""
61
  ---
62
  <sup>**Note:** The pricing information is based on [OpenAI's pricing page](https://openai.com/pricing) as of 12/14/2023.</sup>
63
  <br>
64
- <sub>**Disclaimer:** This application is completely written by GPT-4 from a chat conversation.</sub>
65
  """, unsafe_allow_html=True)
 
2
  import pandas as pd
3
  from transformers import GPT2Tokenizer
4
 
5
+ st.set_page_config(page_title="LLM Cost Estimator", page_icon=":moneybag:")
6
+
7
  # Load the tokenizer
8
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
9
 
 
38
 
39
  # Streamlit App
40
  st.title("GPT/LLM Usage Cost Estimator")
41
+ st.markdown("> _A simple tool to estimate the cost of using OpenAI models based on the number of input and output tokens._")
42
 
43
  # User input
44
+ user_input = st.text_area("", placeholder="Paste your prompt here...")
45
+ estimated_output_tokens = st.number_input("Estimated number of output tokens", min_value=0, value=100)
46
  selected_model = st.selectbox("Select the model", list(rate_prices.keys()))
47
 
48
+ # if st.button("Calculate Cost"):
49
+ if user_input:
50
  input_tokens = count_tokens(user_input)
51
  total_cost = calculate_cost(selected_model, input_tokens, estimated_output_tokens)
52
 
53
+ st.markdown(f"### Estimated Cost: `${total_cost:.2f}`")
54
  # Create a DataFrame for displaying results
55
  results_df = pd.DataFrame({
56
  "Detail": ["Number of Input Tokens", "Estimated Number of Output Tokens", "Estimated Total Cost"],
57
+ "Value": [input_tokens, estimated_output_tokens, f"${total_cost:.4f}"]
58
  })
59
 
60
  # Display the results in a table
 
66
  ---
67
  <sup>**Note:** The pricing information is based on [OpenAI's pricing page](https://openai.com/pricing) as of 12/14/2023.</sup>
68
  <br>
69
+ <sub>**Disclaimer:** This application was completely written by GPT-4 from a chat conversation.</sub>
70
  """, unsafe_allow_html=True)