# Description: LLM Cost Calculator Web App # Author: Vincent CIBELLI (https://www.linkedin.com/in/vincentcibelli/) # Date: 2023-11-01 # Last Modified: 2023-11-01 # License: MIT License import os import streamlit as st import pandas as pd from dotenv import load_dotenv from babel.numbers import format_currency from services.llm_service import LLMService from services.table_service import TableService load_dotenv() llm_service = LLMService() st.set_page_config( page_title="LLM Cost Calculator", page_icon="💸", layout="wide", menu_items={ 'About': "## LLM Cost Calculator\n#### Build {}\nCreated with ❤️ by [Vincent CIBELLI](https://www.linkedin.com/in/vincentcibelli/)".format(os.environ.get("BUILD_VERSION")) } ) st.header("💸 LLM Cost Calculator 💸", divider="green") with st.expander("Last price update ($ currency): {}.".format(os.getenv("PRICE_UPDATE")), expanded=False): st.table(TableService.format_source_table(llm_service.get_list())) st.subheader("Your project information:") with st.expander("#### Average use of your LLM:", expanded=True): col1, col2, col3, col4, col5 = st.columns(5) with col1: request_number = st.number_input("Average request number per hour", min_value=0, value=0, step=100) with col2: request_size = st.number_input("Average input token size", min_value=0, value=0, step=1000) with col3: response_size = st.number_input("Average output token size", min_value=0, value=0, step=1000) with col4: run_hours = st.number_input("Running hours per day", min_value=0, max_value=24, value=0, step=1) with col5: run_day = st.number_input("Running days per week", min_value=0, max_value=7, value=0, step=1) with st.expander("#### LLM models to compare:", expanded=True): llm_chat_list = st.multiselect("Select Chat LLM models", options=[llm.name for llm in llm_service.get_list_by_category("chat")]) llm_text_list = st.multiselect("Select Text LLM models", options=[llm.name for llm in llm_service.get_list_by_category("text")]) result = [] for llm in llm_chat_list + llm_text_list: result.append(llm_service.get_result(llm_service.get_by_name(llm), request_number, request_size, response_size, run_hours, run_day)) if len(result) > 0: st.subheader("Your Cost Result:") st.table(TableService.format_result_table(result))