File size: 1,268 Bytes
7f91398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

# Load the data from the CSV file
@st.cache
def load_data():
    df = pd.read_csv("llm_data.csv")  # Update with your CSV file path
    return df

df = load_data()

# Calculate example cost
def calculate_example_cost(input_text, output_text, input_ratio=0.000001, output_ratio=0.000001):
    input_tokens = len(input_text) / 5
    output_tokens = len(output_text) / 5
    example_cost = (input_tokens * input_ratio) + (output_tokens * output_ratio)
    return example_cost

# Sidebar inputs
input_text = st.sidebar.text_area("Input text")
output_text = st.sidebar.text_area("Output text")

# Calculate example cost for each row
df['Example cost'] = df.apply(lambda row: calculate_example_cost(input_text, output_text, row['Input'], row['Output']), axis=1)

# Display sorted LLM costs
st.write("Sorted LLM Costs:")
sorted_df = df.sort_values(by='Example cost', ascending=False)
st.write(sorted_df[['Company', 'Model', 'Example cost']])

# Plot visualization
st.write("Visualization of LLM Costs:")
plt.figure(figsize=(10, 6))
plt.barh(sorted_df['Model'], sorted_df['Example cost'], color='skyblue')
plt.xlabel('Example Cost')
plt.ylabel('LLM Model')
plt.title('LLM Usage Cost')
st.pyplot(plt)