hlydecker commited on
Commit
7f91398
1 Parent(s): 8ced6f8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Load the data from the CSV file
6
+ @st.cache
7
+ def load_data():
8
+ df = pd.read_csv("llm_data.csv") # Update with your CSV file path
9
+ return df
10
+
11
+ df = load_data()
12
+
13
+ # Calculate example cost
14
+ def calculate_example_cost(input_text, output_text, input_ratio=0.000001, output_ratio=0.000001):
15
+ input_tokens = len(input_text) / 5
16
+ output_tokens = len(output_text) / 5
17
+ example_cost = (input_tokens * input_ratio) + (output_tokens * output_ratio)
18
+ return example_cost
19
+
20
+ # Sidebar inputs
21
+ input_text = st.sidebar.text_area("Input text")
22
+ output_text = st.sidebar.text_area("Output text")
23
+
24
+ # Calculate example cost for each row
25
+ df['Example cost'] = df.apply(lambda row: calculate_example_cost(input_text, output_text, row['Input'], row['Output']), axis=1)
26
+
27
+ # Display sorted LLM costs
28
+ st.write("Sorted LLM Costs:")
29
+ sorted_df = df.sort_values(by='Example cost', ascending=False)
30
+ st.write(sorted_df[['Company', 'Model', 'Example cost']])
31
+
32
+ # Plot visualization
33
+ st.write("Visualization of LLM Costs:")
34
+ plt.figure(figsize=(10, 6))
35
+ plt.barh(sorted_df['Model'], sorted_df['Example cost'], color='skyblue')
36
+ plt.xlabel('Example Cost')
37
+ plt.ylabel('LLM Model')
38
+ plt.title('LLM Usage Cost')
39
+ st.pyplot(plt)