Spaces:
Runtime error
Runtime error
jaifar530
commited on
tr
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ nltk.download('stopwords')
|
|
| 23 |
nltk.download('averaged_perceptron_tagger')
|
| 24 |
|
| 25 |
#version
|
| 26 |
-
st.markdown("v1.
|
| 27 |
|
| 28 |
|
| 29 |
# URL of the text file
|
|
@@ -218,56 +218,57 @@ def add_vectorized_features(df):
|
|
| 218 |
|
| 219 |
# Function define AI_vs_AI_RandomForest_88_Samples
|
| 220 |
def AI_vs_AI_RandomForest_88_Samples(df):
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
with open('AI_vs_AI_RandomForest_88_Samples.pkl', 'wb') as file:
|
| 236 |
-
file.write(response.content)
|
| 237 |
|
| 238 |
# At this point, the pickle file should exist, either it was already there, or it has been downloaded and extracted.
|
| 239 |
with open('AI_vs_AI_RandomForest_88_Samples.pkl', 'rb') as file:
|
| 240 |
clf_loaded = pickle.load(file)
|
| 241 |
|
| 242 |
-
|
| 243 |
|
| 244 |
-
|
| 245 |
-
|
| 246 |
|
|
|
|
| 247 |
predicted_proba = clf_loaded.predict_proba(input_features)
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
|
| 257 |
-
|
| 258 |
-
|
| 259 |
|
| 260 |
-
|
| 261 |
-
|
| 262 |
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
st.write(llm + ': ' + prob)
|
| 266 |
-
st.progress(float(prob.strip('%'))/100)
|
| 267 |
-
return
|
| 268 |
-
except Exception as e:
|
| 269 |
-
st.write(f"An error occurred: {str(e)}")
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
def AI_vs_AI_Ridge_2000_Samples(df):
|
| 273 |
|
|
|
|
| 23 |
nltk.download('averaged_perceptron_tagger')
|
| 24 |
|
| 25 |
#version
|
| 26 |
+
st.markdown("v1.88")
|
| 27 |
|
| 28 |
|
| 29 |
# URL of the text file
|
|
|
|
| 218 |
|
| 219 |
# Function define AI_vs_AI_RandomForest_88_Samples
|
| 220 |
def AI_vs_AI_RandomForest_88_Samples(df):
|
| 221 |
+
|
| 222 |
+
# Check if the file exists
|
| 223 |
+
if not os.path.isfile('AI_vs_AI_RandomForest_88_Samples.pkl'):
|
| 224 |
+
# Download the zip file if it doesn't exist
|
| 225 |
+
url = 'https://jaifar.net/AI_vs_AI_RandomForest_88_Samples.pkl'
|
| 226 |
+
headers = {
|
| 227 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
response = requests.get(url, headers=headers)
|
| 231 |
+
|
| 232 |
+
# Save the file
|
| 233 |
+
with open('AI_vs_AI_RandomForest_88_Samples.pkl', 'wb') as file:
|
| 234 |
+
file.write(response.content)
|
|
|
|
|
|
|
| 235 |
|
| 236 |
# At this point, the pickle file should exist, either it was already there, or it has been downloaded and extracted.
|
| 237 |
with open('AI_vs_AI_RandomForest_88_Samples.pkl', 'rb') as file:
|
| 238 |
clf_loaded = pickle.load(file)
|
| 239 |
|
| 240 |
+
input_features = df['paragraph'].apply(extract_features_AI_vs_AI_RandomForest_88_Samples)
|
| 241 |
|
| 242 |
+
predicted_llm = clf_loaded.predict(input_features)
|
| 243 |
+
st.write(f"Predicted LLM: {predicted_llm[0]}")
|
| 244 |
|
| 245 |
+
try:
|
| 246 |
predicted_proba = clf_loaded.predict_proba(input_features)
|
| 247 |
+
except Exception as e:
|
| 248 |
+
st.write(f"An error occurred: {str(e)}")
|
| 249 |
+
|
| 250 |
+
labels = clf_loaded.classes_
|
| 251 |
|
| 252 |
+
# Create a mapping from old labels to new labels
|
| 253 |
+
label_mapping = {1: 'gpt3', 2: 'gpt4', 3: 'googlebard', 4: 'huggingface'}
|
| 254 |
|
| 255 |
+
# Apply the mapping to the labels
|
| 256 |
+
new_labels = [label_mapping[label] for label in labels]
|
| 257 |
|
| 258 |
+
# Create a dictionary that maps new labels to probabilities
|
| 259 |
+
prob_dict = {k: v for k, v in zip(new_labels, probabilities)}
|
| 260 |
|
| 261 |
+
# Convert probabilities to percentages and sort the dictionary in descending order
|
| 262 |
+
prob_dict = {k: f'{v*100:.2f}%' for k, v in sorted(prob_dict.items(), key=lambda item: item[1], reverse=True)}
|
| 263 |
|
| 264 |
+
# Print the dictionary
|
| 265 |
+
#st.write(prob_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
+
# Create a progress bar and a bar chart for each LLM
|
| 268 |
+
for llm, prob in prob_dict.items():
|
| 269 |
+
st.write(llm + ': ' + prob)
|
| 270 |
+
st.progress(float(prob.strip('%'))/100)
|
| 271 |
+
return
|
| 272 |
|
| 273 |
def AI_vs_AI_Ridge_2000_Samples(df):
|
| 274 |
|