Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
model_data = pd.read_json("model_prices.json") | |
def compute_all(prompt_string, completion_string, model): | |
prompt_cost = calculate_prompt_cost(prompt_string, model) | |
completion_cost = calculate_completion_cost(completion_string, model) | |
prompt_tokens = count_string_tokens(prompt_string, model) | |
completion_tokens = count_string_tokens(completion_string, model) | |
return prompt_tokens, prompt_cost, completion_tokens, completion_cost | |
with gr.Blocks(theme='soft') as demo: | |
gr.Markdown("""### Text-to-$: calculate the price of your LLM runs | |
Based on data from the great [tokencost](https://github.com/AgentOps-AI/tokencost/blob/main/tokencost/model_prices.json). | |
""") | |
with gr.Row(): | |
with gr.Column(): | |
prompt = gr.Textbox(value="Lorem ipsum dolor sit amet...") | |
completion = gr.Textbox(value="...") | |
model = gr.Dropdown(value="gpt-3.5-turbo", choices=["gpt-3.5-turbo", "gpt-3.5-turbo"]) | |
button = gr.Button("Compute costs!") | |
with gr.Column(): | |
with gr.Row(): | |
prompt_tokens = gr.Textbox(interactive=False) | |
prompt_cost = gr.Textbox(interactive=False) | |
with gr.Row(): | |
completion_tokens = gr.Textbox(interactive=False) | |
completion_cost = gr.Textbox(interactive=False) | |
button.click(compute_all, inputs=[prompt, completion, model], outputs=[prompt_tokens, prompt_cost, completion_tokens, completion_cost]) | |
if __name__ == "__main__": | |
demo.launch() |