Arjun Singh commited on
Commit
20d3b15
·
1 Parent(s): 4968d52

Added a condition to do nothing if no error

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -17,10 +17,12 @@ def chat_with_Mixtral(prompt, hugging_face_api_key):
17
  tokens += token
18
  yield tokens
19
  except HfHubHTTPError as e:
20
- if "Authorization header is correct, but the token seems invalid" in str(e):
21
- yield "Error: Invalid API token. Please check your Hugging Face API key."
22
- else:
23
- yield f"Error: An API error occurred - {str(e)}"
 
 
24
 
25
  def clear_fields():
26
  return "", "" # Clear prompt and output, but not the API key
 
17
  tokens += token
18
  yield tokens
19
  except HfHubHTTPError as e:
20
+ error_message = str(e).strip()
21
+ if error_message:
22
+ if "Authorization header is correct, but the token seems invalid" in error_message:
23
+ yield "Error: Invalid API token. Please check your Hugging Face API key."
24
+ else:
25
+ yield f"Error: An API error occurred - {error_message}"
26
 
27
  def clear_fields():
28
  return "", "" # Clear prompt and output, but not the API key