Update app.py
Browse files
app.py
CHANGED
|
@@ -10,8 +10,15 @@ from langchain_groq import ChatGroq
|
|
| 10 |
import chardet
|
| 11 |
import pandas as pd
|
| 12 |
import plotly.graph_objs as go
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def detect_encoding(file_path):
|
| 17 |
with open(file_path, 'rb') as file:
|
|
@@ -106,11 +113,12 @@ def chat_with_models(file, model_a, model_b, api_key, history_a, history_b, ques
|
|
| 106 |
return history_a + [(error_message, None)], history_b + [(error_message, None)], ""
|
| 107 |
|
| 108 |
def load_or_create_df():
|
| 109 |
-
if os.path.exists(
|
| 110 |
-
return pd.read_csv(
|
| 111 |
else:
|
| 112 |
df = pd.DataFrame(columns=['Model A', 'Model B', 'Evaluation', 'Count'])
|
| 113 |
-
|
|
|
|
| 114 |
return df
|
| 115 |
|
| 116 |
def record_evaluation(df, model_a, model_b, evaluation):
|
|
@@ -121,9 +129,15 @@ def record_evaluation(df, model_a, model_b, evaluation):
|
|
| 121 |
'Count': [1]
|
| 122 |
})
|
| 123 |
updated_df = pd.concat([df, new_row], ignore_index=True)
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
return updated_df
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
def update_statistics(df):
|
| 128 |
stats = df.groupby(['Model A', 'Model B', 'Evaluation'])['Count'].sum().reset_index()
|
| 129 |
|
|
@@ -145,7 +159,8 @@ def evaluate(df, model_a, model_b, evaluation):
|
|
| 145 |
models = ["llama3-70b-8192", "mixtral-8x7b-32768", "llama3-8b-8192", "gemma-7b-it"]
|
| 146 |
|
| 147 |
def create_demo():
|
| 148 |
-
print(f"CSV file is located at: {
|
|
|
|
| 149 |
|
| 150 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 151 |
gr.Markdown("# Choose two models to compare")
|
|
@@ -196,7 +211,7 @@ def create_demo():
|
|
| 196 |
return demo
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
-
print(f"CSV file is located at: {
|
| 200 |
demo = create_demo()
|
| 201 |
demo.launch(share=True)
|
| 202 |
else:
|
|
|
|
| 10 |
import chardet
|
| 11 |
import pandas as pd
|
| 12 |
import plotly.graph_objs as go
|
| 13 |
+
import shutil
|
| 14 |
|
| 15 |
+
TMP_CSV_PATH = "/tmp/evaluations.csv"
|
| 16 |
+
PERSISTENT_CSV_PATH = "/home/user/evaluations.csv"
|
| 17 |
+
|
| 18 |
+
def ensure_directory_exists(file_path):
|
| 19 |
+
directory = os.path.dirname(file_path)
|
| 20 |
+
if not os.path.exists(directory):
|
| 21 |
+
os.makedirs(directory)
|
| 22 |
|
| 23 |
def detect_encoding(file_path):
|
| 24 |
with open(file_path, 'rb') as file:
|
|
|
|
| 113 |
return history_a + [(error_message, None)], history_b + [(error_message, None)], ""
|
| 114 |
|
| 115 |
def load_or_create_df():
|
| 116 |
+
if os.path.exists(PERSISTENT_CSV_PATH):
|
| 117 |
+
return pd.read_csv(PERSISTENT_CSV_PATH)
|
| 118 |
else:
|
| 119 |
df = pd.DataFrame(columns=['Model A', 'Model B', 'Evaluation', 'Count'])
|
| 120 |
+
ensure_directory_exists(PERSISTENT_CSV_PATH)
|
| 121 |
+
df.to_csv(PERSISTENT_CSV_PATH, index=False)
|
| 122 |
return df
|
| 123 |
|
| 124 |
def record_evaluation(df, model_a, model_b, evaluation):
|
|
|
|
| 129 |
'Count': [1]
|
| 130 |
})
|
| 131 |
updated_df = pd.concat([df, new_row], ignore_index=True)
|
| 132 |
+
ensure_directory_exists(TMP_CSV_PATH)
|
| 133 |
+
updated_df.to_csv(TMP_CSV_PATH, index=False)
|
| 134 |
+
copy_to_persistent_storage()
|
| 135 |
return updated_df
|
| 136 |
|
| 137 |
+
def copy_to_persistent_storage():
|
| 138 |
+
ensure_directory_exists(PERSISTENT_CSV_PATH)
|
| 139 |
+
shutil.copy2(TMP_CSV_PATH, PERSISTENT_CSV_PATH)
|
| 140 |
+
|
| 141 |
def update_statistics(df):
|
| 142 |
stats = df.groupby(['Model A', 'Model B', 'Evaluation'])['Count'].sum().reset_index()
|
| 143 |
|
|
|
|
| 159 |
models = ["llama3-70b-8192", "mixtral-8x7b-32768", "llama3-8b-8192", "gemma-7b-it"]
|
| 160 |
|
| 161 |
def create_demo():
|
| 162 |
+
print(f"Temporary CSV file is located at: {TMP_CSV_PATH}")
|
| 163 |
+
print(f"Persistent CSV file is located at: {PERSISTENT_CSV_PATH}")
|
| 164 |
|
| 165 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 166 |
gr.Markdown("# Choose two models to compare")
|
|
|
|
| 211 |
return demo
|
| 212 |
|
| 213 |
if __name__ == "__main__":
|
| 214 |
+
print(f"CSV file is located at: {PERSISTENT_CSV_PATH}")
|
| 215 |
demo = create_demo()
|
| 216 |
demo.launch(share=True)
|
| 217 |
else:
|