monsimas commited on
Commit
9634edc
1 Parent(s): 0172d3a

random improvements

Browse files
app.py CHANGED
@@ -12,23 +12,23 @@ import logging
12
  from collections import defaultdict
13
 
14
 
15
- # Configure the root logger's level
16
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
17
 
18
- # File handler
19
  file_handler = logging.FileHandler('categorization_logs.log')
20
  file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
21
 
22
- # Console handler
23
  console_handler = logging.StreamHandler()
24
  console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
25
 
26
- # Adding handlers to the root logger
27
  logger = logging.getLogger()
28
  logger.addHandler(file_handler)
29
  logger.addHandler(console_handler)
30
 
31
- # Adjust the logging level for httpx
32
  logging.getLogger("httpx").setLevel(logging.WARNING)
33
 
34
  os.environ['MISTRAL_API_KEY'] = 'd2unb3id1dlPdHkIZOO6Okz3VwZFYZPN'
@@ -41,80 +41,77 @@ client = MistralClient(api_key=api_key)
41
  def make_request_with_retry(client, model, messages, temperature=0.7, retries=3, delay=60):
42
  for attempt in range(retries):
43
  try:
44
- logging.info(f"Attempting to send request to model {model}, attempt {attempt + 1}")
45
  response = client.chat(model=model, messages=messages, temperature=temperature)
46
  return response
47
  except MistralAPIStatusException as e:
48
- logging.warning(f"Request failed with error: {e}. Retrying after {delay} seconds...")
49
  time.sleep(delay)
50
  except Exception as e:
51
- logging.error(f"An unexpected error occurred: {e}", exc_info=True)
52
  raise
53
- logging.error("Max retries exceeded without success.")
54
- raise Exception("Max retries exceeded")
55
 
56
-
57
- def get_consistent_categories(proposal, categories, language, client, model, temperature, allow_multiple_categories, validation_retries, coinciding_retries_threshold, max_attempts=5):
58
  proposal_str = str(proposal)
59
 
60
  responses = []
61
  model_responses = []
62
 
63
- # Collect categorization responses
64
  for _ in range(max_attempts):
65
- prompt = generate_prompt(proposal_str, categories, language)
66
- messages = [
67
- ChatMessage(role="system", content="Your task is to categorize the given proposal into one or more of the following categories: {categories}. Respond with only the category name(s), separated by commas if multiple categories apply and keep the language of the prompt."),
68
- ChatMessage(role="user", content=prompt)
69
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  response = make_request_with_retry(client, model, messages, temperature)
71
- category_response = parse_category(response.choices[0].message.content, categories)
72
- responses.extend(category_response)
73
- model_responses.append(response.choices[0].message.content)
 
 
 
 
 
 
74
 
75
  if allow_multiple_categories:
76
- # Check if any category is consistently present across all responses
77
- category_counts = Counter(responses)
78
- consistent_category = [category for category, count in category_counts.items() if count == max_attempts]
79
-
80
- if consistent_category:
81
- # If a consistent category is found, return it
82
- return ', '.join(consistent_category), model_responses
83
-
84
- # If no consistent category is found, proceed with co-occurrence analysis
85
- category_co_occurrences = defaultdict(int)
86
- for response in responses:
87
- for category in response:
88
- for other_category in response:
89
- if category != other_category:
90
- category_co_occurrences[(category, other_category)] += 1
91
-
92
- selected_categories = []
93
- for category in categories:
94
- category_support = sum(category_co_occurrences[(category, other)] for other in categories)
95
- if category_support >= coinciding_retries_threshold:
96
- selected_categories.append(category)
97
-
98
- if not selected_categories:
99
- category = "No Consistent Categories Found"
100
- else:
101
- category = ', '.join(selected_categories)
102
-
103
  return category, model_responses
104
  else:
105
- # Return the single most common category
106
- most_common, num_most_common = category_counts.most_common(1)[0]
107
- if num_most_common <= 1:
108
- # If the most common category is not clearly dominant, consider asking the model for a suggestion
109
- suggestion_prompt = f"Given the proposal: '{proposal_str}', which category fits best? {', '.join(categories)}"
110
- messages = [ChatMessage(role="system", content="Suggest a category."), ChatMessage(role="user", content=suggestion_prompt)]
111
- suggestion_response = make_request_with_retry(client, model, messages, temperature)
112
- most_common = parse_category(suggestion_response.choices[0].message.content, categories)
113
-
114
- logging.info(f"Consistent category '{most_common}' found for proposal: {proposal_str[:30]}...")
115
- return most_common if most_common in categories else "Category Not Found"
116
-
117
-
118
  def parse_category(response_text, categories):
119
  response_text_lower = response_text.lower()
120
  found_categories = []
@@ -122,30 +119,31 @@ def parse_category(response_text, categories):
122
  for category in categories:
123
  category_lower = category.lower()
124
  if category_lower in response_text_lower:
125
- # Check if the category is a standalone word or phrase
126
  if re.search(r'\b' + re.escape(category_lower) + r'\b', response_text_lower):
127
  found_categories.append(category)
128
  else:
129
- # Check if the category is a substring of a word
130
  if re.search(re.escape(category_lower), response_text_lower):
131
  found_categories.append(category)
132
 
133
  return found_categories
134
 
135
- language_prompts = {
136
- "English": {
137
- "prompt_template": """
138
- Your task is to categorize the given proposal into one or more of the following categories: {categories}. Respond with only the category name(s), separated by commas if multiple categories apply.
139
 
140
- Example:
141
- Proposal: "Planting trees in urban areas to improve air quality."
142
- Response: ecology
143
 
144
- Proposal: "{proposal}"
145
- """
146
- },
147
- "French": {
148
- "prompt_template": """
 
 
149
  Votre tâche est de catégoriser la proposition donnée dans une ou plusieurs des catégories suivantes : {categories}. Répondez uniquement avec le(s) nom(s) de la/des catégorie(s), séparés par des virgules si plusieurs catégories s'appliquent.
150
 
151
  Exemple :
@@ -154,21 +152,20 @@ language_prompts = {
154
 
155
  Proposition : "{proposal}"
156
  """
157
- }
 
 
158
 
159
- }
 
 
160
 
161
- def generate_prompt(proposal, categories, language):
162
- # Check if the selected language is supported and has a prompt template
163
- if language in language_prompts and "prompt_template" in language_prompts[language]:
164
- prompt_template = language_prompts[language]["prompt_template"]
165
- categories_str = ", ".join(categories) # Convert categories list to a comma-separated string
166
- prompt = prompt_template.format(categories=categories_str, proposal=proposal)
167
- return prompt
168
- else:
169
- # Fallback or error handling if the language or template is not found
170
- logging.error(f"Language template for '{language}' not found.")
171
- return "" # Return an empty string or a default prompt
172
 
173
 
174
  def get_parameters(index):
@@ -196,7 +193,7 @@ def get_parameters(index):
196
  return temperature, validation_retries, coinciding_retries_threshold
197
 
198
 
199
- def categorize_proposals(excel_file, categories, proposal_column_index=0, index=1, language="English", allow_multiple_categories=False):
200
  df = pd.read_excel(excel_file, header=None)
201
  proposals = df.iloc[:, proposal_column_index].tolist()
202
  categorized_results = []
@@ -204,38 +201,56 @@ def categorize_proposals(excel_file, categories, proposal_column_index=0, index=
204
  temperature, validation_retries, coinciding_retries_threshold = get_parameters(index)
205
 
206
  for proposal in proposals:
207
- category, model_responses = get_consistent_categories(proposal, categories, language, client, model, temperature, allow_multiple_categories, validation_retries, coinciding_retries_threshold)
208
  if ', ' in category:
209
  categorized_results.append((proposal, category, ', '.join(model_responses)))
210
  else:
211
  categorized_results.append((proposal, category, '; '.join(model_responses)))
212
 
213
- return pd.DataFrame(categorized_results, columns=['Proposal', 'Category', 'Model Responses'])
214
-
215
-
216
 
217
 
218
 
219
-
220
- def gradio_interface(excel_file, categories, index, language, allow_multiple_categories):
221
- categories_list = categories.split(',')
222
- temperature, validation_retries, coinciding_retries_threshold = get_parameters(index)
223
- results_df = categorize_proposals(excel_file.name, categories_list, index=index, language=language, allow_multiple_categories=allow_multiple_categories)
224
- return results_df.to_html()
225
-
 
 
 
226
 
227
  iface = gr.Interface(
228
  fn=gradio_interface,
229
  inputs=[
230
- gr.File(label="Upload Excel File"),
231
- gr.Textbox(label="Enter the categories (separated by commas)"),
232
- gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Robustness Index"),
233
- gr.Dropdown(choices=["English", "French"], label="Language"),
234
- gr.Checkbox(label="Allow Multiple Categories")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  ],
236
- outputs=gr.HTML(label="Categorization Results"),
237
- title="Proposal Categorization Tool",
238
- description="Upload an Excel file of proposals, specify the categories, adjust the robustness index, select the language, and indicate if multiple categories per proposal are allowed. Increase the index if the results are incomplete or insufficient."
 
 
 
239
  )
240
 
241
  iface.launch()
 
12
  from collections import defaultdict
13
 
14
 
15
+ # Configurer le niveau du logger racine
16
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
17
 
18
+ # Gestionnaire de fichiers
19
  file_handler = logging.FileHandler('categorization_logs.log')
20
  file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
21
 
22
+ # Gestionnaire de console
23
  console_handler = logging.StreamHandler()
24
  console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
25
 
26
+ # Ajout des gestionnaires au logger racine
27
  logger = logging.getLogger()
28
  logger.addHandler(file_handler)
29
  logger.addHandler(console_handler)
30
 
31
+ # Ajuster le niveau de journalisation pour httpx
32
  logging.getLogger("httpx").setLevel(logging.WARNING)
33
 
34
  os.environ['MISTRAL_API_KEY'] = 'd2unb3id1dlPdHkIZOO6Okz3VwZFYZPN'
 
41
  def make_request_with_retry(client, model, messages, temperature=0.7, retries=3, delay=60):
42
  for attempt in range(retries):
43
  try:
44
+ logging.info(f"Tentative d'envoi de la requête au modèle {model}, essai {attempt + 1}")
45
  response = client.chat(model=model, messages=messages, temperature=temperature)
46
  return response
47
  except MistralAPIStatusException as e:
48
+ logging.warning(f"La requête a échoué avec l'erreur : {e}. Nouvelle tentative après {delay} secondes...")
49
  time.sleep(delay)
50
  except Exception as e:
51
+ logging.error(f"Une erreur inattendue s'est produite : {e}", exc_info=True)
52
  raise
53
+ logging.error("Le nombre maximal de tentatives a été atteint sans succès.")
54
+ raise Exception("Le nombre maximal de tentatives a été atteint")
55
 
56
+ def get_consistent_categories(proposal, categories, client, model, temperature, allow_multiple_categories, validation_retries, coinciding_retries_threshold, max_attempts=5):
 
57
  proposal_str = str(proposal)
58
 
59
  responses = []
60
  model_responses = []
61
 
62
+ # Collecter les réponses de catégorisation
63
  for _ in range(max_attempts):
64
+ if allow_multiple_categories:
65
+ system_prompt = f"""
66
+ Votre tâche est de catégoriser la proposition donnée dans une ou plusieurs des catégories suivantes : {', '.join(categories)}.
67
+ Répondez uniquement avec le(s) nom(s) de la/des catégorie(s), séparés par des virgules si plusieurs catégories s'appliquent.
68
+
69
+ Exemple :
70
+ Proposition : "Planter des arbres dans les zones urbaines pour améliorer la qualité de l'air."
71
+ Réponse : écologie
72
+ """
73
+ user_prompt = f"Proposition : \"{proposal_str}\""
74
+ messages = [
75
+ ChatMessage(role="system", content=system_prompt),
76
+ ChatMessage(role="user", content=user_prompt)
77
+ ]
78
+ else:
79
+ system_prompt = f"""
80
+ Votre tâche est de catégoriser la proposition donnée dans une seule des catégories suivantes : {', '.join(categories)}.
81
+ Répondez uniquement avec le nom de la catégorie la plus appropriée.
82
+
83
+ Exemple :
84
+ Proposition : "Planter des arbres dans les zones urbaines pour améliorer la qualité de l'air."
85
+ Réponse : écologie
86
+ """
87
+ user_prompt = f"Proposition : \"{proposal_str}\""
88
+ messages = [
89
+ ChatMessage(role="system", content=system_prompt),
90
+ ChatMessage(role="user", content=user_prompt)
91
+ ]
92
+
93
  response = make_request_with_retry(client, model, messages, temperature)
94
+ if response and response.choices and response.choices[0].message.content:
95
+ category_response = parse_category(response.choices[0].message.content, categories)
96
+ responses.extend(category_response)
97
+ model_responses.append(response.choices[0].message.content)
98
+ else:
99
+ logging.warning(f"Réponse incomplète ou vide reçue pour la proposition : {proposal_str[:30]}...")
100
+
101
+ if not responses:
102
+ return "Aucune catégorie trouvée", model_responses
103
 
104
  if allow_multiple_categories:
105
+ # Retourner toutes les catégories uniques trouvées
106
+ selected_categories = list(set(responses))
107
+ category = ', '.join(selected_categories)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  return category, model_responses
109
  else:
110
+ # Retourner la catégorie la plus fréquente
111
+ category_counts = Counter(responses)
112
+ most_common, _ = category_counts.most_common(1)[0]
113
+ return most_common, model_responses
114
+
 
 
 
 
 
 
 
 
115
  def parse_category(response_text, categories):
116
  response_text_lower = response_text.lower()
117
  found_categories = []
 
119
  for category in categories:
120
  category_lower = category.lower()
121
  if category_lower in response_text_lower:
122
+ # Vérifier si la catégorie est un mot ou une phrase autonome
123
  if re.search(r'\b' + re.escape(category_lower) + r'\b', response_text_lower):
124
  found_categories.append(category)
125
  else:
126
+ # Vérifier si la catégorie est une sous-chaîne d'un mot
127
  if re.search(re.escape(category_lower), response_text_lower):
128
  found_categories.append(category)
129
 
130
  return found_categories
131
 
132
+ language_prompt = {
133
+ "prompt_template": """
134
+ Votre tâche est de catégoriser la proposition donnée dans une ou plusieurs des catégories suivantes : {categories}. Répondez uniquement avec le(s) nom(s) de la/des catégorie(s), séparés par des virgules si plusieurs catégories s'appliquent.
 
135
 
136
+ Exemple :
137
+ Proposition : "Planter des arbres dans les zones urbaines pour améliorer la qualité de l'air."
138
+ Réponse : écologie
139
 
140
+ Proposition : "{proposal}"
141
+ """
142
+ }
143
+
144
+ def generate_prompt(proposal, categories, allow_multiple_categories=False):
145
+ if allow_multiple_categories:
146
+ prompt_template = """
147
  Votre tâche est de catégoriser la proposition donnée dans une ou plusieurs des catégories suivantes : {categories}. Répondez uniquement avec le(s) nom(s) de la/des catégorie(s), séparés par des virgules si plusieurs catégories s'appliquent.
148
 
149
  Exemple :
 
152
 
153
  Proposition : "{proposal}"
154
  """
155
+ else:
156
+ prompt_template = """
157
+ Votre tâche est de catégoriser la proposition donnée dans une seule des catégories suivantes : {categories}. Répondez uniquement avec le nom de la catégorie la plus appropriée.
158
 
159
+ Exemple :
160
+ Proposition : "Planter des arbres dans les zones urbaines pour améliorer la qualité de l'air."
161
+ Réponse : écologie
162
 
163
+ Proposition : "{proposal}"
164
+ """
165
+
166
+ categories_str = ", ".join(categories) # Convertir la liste des catégories en une chaîne séparée par des virgules
167
+ prompt = prompt_template.format(categories=categories_str, proposal=proposal)
168
+ return prompt
 
 
 
 
 
169
 
170
 
171
  def get_parameters(index):
 
193
  return temperature, validation_retries, coinciding_retries_threshold
194
 
195
 
196
+ def categorize_proposals(excel_file, categories, proposal_column_index=0, index=1, allow_multiple_categories=False):
197
  df = pd.read_excel(excel_file, header=None)
198
  proposals = df.iloc[:, proposal_column_index].tolist()
199
  categorized_results = []
 
201
  temperature, validation_retries, coinciding_retries_threshold = get_parameters(index)
202
 
203
  for proposal in proposals:
204
+ category, model_responses = get_consistent_categories(proposal, categories, client, model, temperature, allow_multiple_categories, validation_retries, coinciding_retries_threshold)
205
  if ', ' in category:
206
  categorized_results.append((proposal, category, ', '.join(model_responses)))
207
  else:
208
  categorized_results.append((proposal, category, '; '.join(model_responses)))
209
 
210
+ return pd.DataFrame(categorized_results, columns=['Proposition', 'Catégorie', 'Réponses du modèle'])
 
 
211
 
212
 
213
 
214
+ def gradio_interface(excel_file, categories, index, allow_multiple_categories):
215
+ try:
216
+ categories_list = categories.split(',')
217
+ temperature, validation_retries, coinciding_retries_threshold = get_parameters(index)
218
+
219
+ results_df = categorize_proposals(excel_file.name, categories_list, index=index, allow_multiple_categories=allow_multiple_categories)
220
+ return results_df.to_html(index=False)
221
+ except Exception as e:
222
+ logging.error(f"Une erreur s'est produite : {e}")
223
+ return "Une erreur s'est produite lors du traitement de la requête. Veuillez réessayer plus tard."
224
 
225
  iface = gr.Interface(
226
  fn=gradio_interface,
227
  inputs=[
228
+ gr.File(label="Télécharger le fichier Excel", file_types=["xlsx"], file_count="single"),
229
+ gr.Textbox(
230
+ label="Entrez les catégories (séparées par des virgules)",
231
+ placeholder="Entrez les catégories...",
232
+ lines=2,
233
+ max_lines=5,
234
+ ),
235
+ gr.Slider(
236
+ minimum=1,
237
+ maximum=5,
238
+ step=1,
239
+ value=3,
240
+ label="Indice de robustesse",
241
+ info="Ajustez l'indice de robustesse pour contrôler la précision de la catégorisation. Des valeurs plus élevées augmentent la précision mais peuvent prendre plus de temps à traiter.",
242
+ ),
243
+ gr.Checkbox(
244
+ label="Autoriser plusieurs catégories",
245
+ info="Cochez cette case si une proposition peut appartenir à plusieurs catégories.",
246
+ ),
247
  ],
248
+ outputs=gr.HTML(label="Résultats de la catégorisation"),
249
+ title="Outil de catégorisation des propositions",
250
+ description="Téléchargez un fichier Excel de propositions, spécifiez les catégories, ajustez l'indice de robustesse et indiquez si plusieurs catégories par proposition sont autorisées.",
251
+ cache_examples=False,
252
+ allow_flagging="never",
253
+ flagging_options=["incorrect", "ambigu"],
254
  )
255
 
256
  iface.launch()
categorization_logs.log CHANGED
@@ -305,3 +305,219 @@ Traceback (most recent call last):
305
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 98, in _request
306
  raise MistralException(
307
  mistralai.exceptions.MistralException: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 98, in _request
306
  raise MistralException(
307
  mistralai.exceptions.MistralException: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
308
+ 2024-03-05 16:23:04,597 - ERROR - An error occurred: cannot access local variable 'category_counts' where it is not associated with a value
309
+ 2024-03-05 16:24:55,715 - ERROR - An error occurred: make_request_with_retry() got an unexpected keyword argument 'timeout'
310
+ 2024-03-05 16:25:52,507 - ERROR - An error occurred: unhashable type: 'list'
311
+ 2024-03-05 16:26:00,537 - ERROR - An unexpected error occurred: MistralClient.chat() got an unexpected keyword argument 'request_timeout'
312
+ Traceback (most recent call last):
313
+ File "/Users/simonaszilinskas/open-source-categories/categorizer-les-propals/app.py", line 45, in make_request_with_retry
314
+ response = client.chat(model=model, messages=messages, temperature=temperature, request_timeout=timeout)
315
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
316
+ TypeError: MistralClient.chat() got an unexpected keyword argument 'request_timeout'
317
+ 2024-03-05 16:26:00,541 - ERROR - An error occurred: MistralClient.chat() got an unexpected keyword argument 'request_timeout'
318
+ 2024-03-05 16:26:59,778 - ERROR - An error occurred: list index out of range
319
+ 2024-03-05 16:28:03,073 - ERROR - An error occurred: list index out of range
320
+ 2024-03-05 16:34:04,632 - ERROR - An unexpected error occurred: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
321
+ Traceback (most recent call last):
322
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions
323
+ yield
324
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 228, in handle_request
325
+ resp = self._pool.handle_request(req)
326
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
327
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
328
+ raise exc
329
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
330
+ response = connection.handle_request(request)
331
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
332
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
333
+ return self._connection.handle_request(request)
334
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 133, in handle_request
336
+ raise exc
337
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 111, in handle_request
338
+ ) = self._receive_response_headers(**kwargs)
339
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
340
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 176, in _receive_response_headers
341
+ event = self._receive_event(timeout=timeout)
342
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
343
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 226, in _receive_event
344
+ raise RemoteProtocolError(msg)
345
+ httpcore.RemoteProtocolError: Server disconnected without sending a response.
346
+
347
+ The above exception was the direct cause of the following exception:
348
+
349
+ Traceback (most recent call last):
350
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 86, in _request
351
+ response = self._client.request(
352
+ ^^^^^^^^^^^^^^^^^^^^^
353
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 814, in request
354
+ return self.send(request, auth=auth, follow_redirects=follow_redirects)
355
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
356
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
357
+ response = self._send_handling_auth(
358
+ ^^^^^^^^^^^^^^^^^^^^^^^^^
359
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
360
+ response = self._send_handling_redirects(
361
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
362
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
363
+ response = self._send_single_request(request)
364
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
365
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 1002, in _send_single_request
366
+ response = transport.handle_request(request)
367
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
368
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 227, in handle_request
369
+ with map_httpcore_exceptions():
370
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
371
+ self.gen.throw(typ, value, traceback)
372
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions
373
+ raise mapped_exc(message) from exc
374
+ httpx.RemoteProtocolError: Server disconnected without sending a response.
375
+
376
+ The above exception was the direct cause of the following exception:
377
+
378
+ Traceback (most recent call last):
379
+ File "/Users/simonaszilinskas/open-source-categories/categorizer-les-propals/app.py", line 45, in make_request_with_retry
380
+ response = client.chat(model=model, messages=messages, temperature=temperature)
381
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
382
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 160, in chat
383
+ for response in single_response:
384
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 98, in _request
385
+ raise MistralException(
386
+ mistralai.exceptions.MistralException: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
387
+ 2024-03-05 16:34:04,658 - ERROR - An error occurred: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
388
+ 2024-03-11 15:06:35,679 - ERROR - An unexpected error occurred: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
389
+ Traceback (most recent call last):
390
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions
391
+ yield
392
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 228, in handle_request
393
+ resp = self._pool.handle_request(req)
394
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
395
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
396
+ raise exc
397
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
398
+ response = connection.handle_request(request)
399
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
400
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
401
+ return self._connection.handle_request(request)
402
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
403
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 133, in handle_request
404
+ raise exc
405
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 111, in handle_request
406
+ ) = self._receive_response_headers(**kwargs)
407
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
408
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 176, in _receive_response_headers
409
+ event = self._receive_event(timeout=timeout)
410
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
411
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 226, in _receive_event
412
+ raise RemoteProtocolError(msg)
413
+ httpcore.RemoteProtocolError: Server disconnected without sending a response.
414
+
415
+ The above exception was the direct cause of the following exception:
416
+
417
+ Traceback (most recent call last):
418
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 86, in _request
419
+ response = self._client.request(
420
+ ^^^^^^^^^^^^^^^^^^^^^
421
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 814, in request
422
+ return self.send(request, auth=auth, follow_redirects=follow_redirects)
423
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
424
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
425
+ response = self._send_handling_auth(
426
+ ^^^^^^^^^^^^^^^^^^^^^^^^^
427
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
428
+ response = self._send_handling_redirects(
429
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
430
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
431
+ response = self._send_single_request(request)
432
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
433
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 1002, in _send_single_request
434
+ response = transport.handle_request(request)
435
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
436
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 227, in handle_request
437
+ with map_httpcore_exceptions():
438
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
439
+ self.gen.throw(typ, value, traceback)
440
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions
441
+ raise mapped_exc(message) from exc
442
+ httpx.RemoteProtocolError: Server disconnected without sending a response.
443
+
444
+ The above exception was the direct cause of the following exception:
445
+
446
+ Traceback (most recent call last):
447
+ File "/Users/simonaszilinskas/open-source-categories/categorizer-les-propals/app.py", line 45, in make_request_with_retry
448
+ response = client.chat(model=model, messages=messages, temperature=temperature)
449
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
450
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 160, in chat
451
+ for response in single_response:
452
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 98, in _request
453
+ raise MistralException(
454
+ mistralai.exceptions.MistralException: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
455
+ 2024-03-11 15:06:35,698 - ERROR - An error occurred: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
456
+ 2024-03-11 15:12:46,838 - ERROR - An unexpected error occurred: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
457
+ Traceback (most recent call last):
458
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions
459
+ yield
460
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 228, in handle_request
461
+ resp = self._pool.handle_request(req)
462
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
463
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
464
+ raise exc
465
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
466
+ response = connection.handle_request(request)
467
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
468
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
469
+ return self._connection.handle_request(request)
470
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
471
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 133, in handle_request
472
+ raise exc
473
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 111, in handle_request
474
+ ) = self._receive_response_headers(**kwargs)
475
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
476
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 176, in _receive_response_headers
477
+ event = self._receive_event(timeout=timeout)
478
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
479
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpcore/_sync/http11.py", line 226, in _receive_event
480
+ raise RemoteProtocolError(msg)
481
+ httpcore.RemoteProtocolError: Server disconnected without sending a response.
482
+
483
+ The above exception was the direct cause of the following exception:
484
+
485
+ Traceback (most recent call last):
486
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 86, in _request
487
+ response = self._client.request(
488
+ ^^^^^^^^^^^^^^^^^^^^^
489
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 814, in request
490
+ return self.send(request, auth=auth, follow_redirects=follow_redirects)
491
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
492
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
493
+ response = self._send_handling_auth(
494
+ ^^^^^^^^^^^^^^^^^^^^^^^^^
495
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
496
+ response = self._send_handling_redirects(
497
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
498
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
499
+ response = self._send_single_request(request)
500
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
501
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_client.py", line 1002, in _send_single_request
502
+ response = transport.handle_request(request)
503
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
504
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 227, in handle_request
505
+ with map_httpcore_exceptions():
506
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 155, in __exit__
507
+ self.gen.throw(typ, value, traceback)
508
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions
509
+ raise mapped_exc(message) from exc
510
+ httpx.RemoteProtocolError: Server disconnected without sending a response.
511
+
512
+ The above exception was the direct cause of the following exception:
513
+
514
+ Traceback (most recent call last):
515
+ File "/Users/simonaszilinskas/open-source-categories/categorizer-les-propals/app.py", line 45, in make_request_with_retry
516
+ response = client.chat(model=model, messages=messages, temperature=temperature)
517
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
518
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 160, in chat
519
+ for response in single_response:
520
+ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mistralai/client.py", line 98, in _request
521
+ raise MistralException(
522
+ mistralai.exceptions.MistralException: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
523
+ 2024-03-11 15:12:46,859 - ERROR - An error occurred: Unexpected exception (RemoteProtocolError): Server disconnected without sending a response.
gradio_cached_examples/18/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Categorization Results,flag,username,timestamp
2
+ An error occurred while processing the request. Please try again later.,,,2024-03-11 15:06:35.706140
sample-proposals.xls ADDED
Binary file (21.5 kB). View file