RajanMalaviya commited on
Commit
da26974
·
verified ·
1 Parent(s): ed3090c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -16,7 +16,7 @@ import asyncio
16
  import psutil
17
  import cachetools
18
  import hashlib
19
- from huggingface_hub import InferenceClient, HTTPError
20
 
21
  app = FastAPI()
22
 
@@ -158,8 +158,8 @@ async def process_with_llm(filename: str, raw_text: str):
158
  structured_data_cache[text_hash] = structured_data
159
  logger.info(f"LLM API processing for {filename} with {model}, attempt {attempt+1}, took {time.time() - start_time:.2f} seconds, {log_memory_usage()}")
160
  return structured_data
161
- except HTTPError as e:
162
- if e.status_code == 429: # Rate limit
163
  logger.warning(f"Rate limit hit for {filename} with {model}, attempt {attempt+1}: {str(e)}, {log_memory_usage()}")
164
  if attempt == 1:
165
  break
@@ -167,9 +167,6 @@ async def process_with_llm(filename: str, raw_text: str):
167
  else:
168
  logger.warning(f"LLM API processing failed for {filename} with {model}, attempt {attempt+1}: {str(e)}, {log_memory_usage()}")
169
  break
170
- except Exception as e:
171
- logger.warning(f"LLM API processing failed for {filename} with {model}, attempt {attempt+1}: {str(e)}, {log_memory_usage()}")
172
- break
173
 
174
  # If all models fail
175
  error_msg = "All LLM API models failed. Check model availability, authentication, or rate limits."
 
16
  import psutil
17
  import cachetools
18
  import hashlib
19
+ from huggingface_hub import InferenceClient
20
 
21
  app = FastAPI()
22
 
 
158
  structured_data_cache[text_hash] = structured_data
159
  logger.info(f"LLM API processing for {filename} with {model}, attempt {attempt+1}, took {time.time() - start_time:.2f} seconds, {log_memory_usage()}")
160
  return structured_data
161
+ except Exception as e:
162
+ if hasattr(e, 'response') and e.response.status_code == 429: # Rate limit
163
  logger.warning(f"Rate limit hit for {filename} with {model}, attempt {attempt+1}: {str(e)}, {log_memory_usage()}")
164
  if attempt == 1:
165
  break
 
167
  else:
168
  logger.warning(f"LLM API processing failed for {filename} with {model}, attempt {attempt+1}: {str(e)}, {log_memory_usage()}")
169
  break
 
 
 
170
 
171
  # If all models fail
172
  error_msg = "All LLM API models failed. Check model availability, authentication, or rate limits."