Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import tiktoken
|
4 |
-
|
|
|
5 |
|
6 |
def process_csv(file, calculate_openai, openai_model, calculate_anthropic, anthropic_model):
|
7 |
# Check if file is uploaded
|
@@ -41,14 +42,23 @@ def process_csv(file, calculate_openai, openai_model, calculate_anthropic, anthr
|
|
41 |
output += f"\n**Total OpenAI Tokens ({openai_model}): {total_tokens_openai}**\n\n"
|
42 |
|
43 |
if calculate_anthropic:
|
44 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
token_counts_anthropic = {}
|
46 |
total_tokens_anthropic = 0
|
47 |
|
|
|
48 |
for col in df.columns:
|
49 |
tokens_col_anthropic = 0
|
50 |
for cell in df[col].astype(str):
|
51 |
-
tokens_anthropic =
|
52 |
tokens_col_anthropic += tokens_anthropic
|
53 |
token_counts_anthropic[col] = tokens_col_anthropic
|
54 |
total_tokens_anthropic += tokens_col_anthropic
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import tiktoken
|
4 |
+
import anthropic
|
5 |
+
#import os
|
6 |
|
7 |
def process_csv(file, calculate_openai, openai_model, calculate_anthropic, anthropic_model):
|
8 |
# Check if file is uploaded
|
|
|
42 |
output += f"\n**Total OpenAI Tokens ({openai_model}): {total_tokens_openai}**\n\n"
|
43 |
|
44 |
if calculate_anthropic:
|
45 |
+
# Get the Anthropic API key from environment variables
|
46 |
+
#anthropic_api_key = os.environ.get("ANTHROPIC_API_KEY")
|
47 |
+
#if not anthropic_api_key:
|
48 |
+
# return "Please set the ANTHROPIC_API_KEY environment variable."
|
49 |
+
|
50 |
+
# Initialize the Anthropic client
|
51 |
+
#client = anthropic.Anthropic(api_key=anthropic_api_key)
|
52 |
+
client = anthropic.Anthropic()
|
53 |
+
|
54 |
token_counts_anthropic = {}
|
55 |
total_tokens_anthropic = 0
|
56 |
|
57 |
+
# Iterate over columns
|
58 |
for col in df.columns:
|
59 |
tokens_col_anthropic = 0
|
60 |
for cell in df[col].astype(str):
|
61 |
+
tokens_anthropic = client.count_tokens(cell)
|
62 |
tokens_col_anthropic += tokens_anthropic
|
63 |
token_counts_anthropic[col] = tokens_col_anthropic
|
64 |
total_tokens_anthropic += tokens_col_anthropic
|