hlydecker's picture
Create app.py
7f91398 verified
raw
history blame
No virus
1.27 kB
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)