ccibeekeoc42 commited on
Commit
1111f2b
·
verified ·
1 Parent(s): 3421ba2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import openai
3
- from openai.error import InternalServerError # Import the error class
4
  import torch
5
  from transformers import pipeline
6
 
@@ -48,7 +47,6 @@ client = OpenAI(
48
 
49
  # return "".join(full_response)
50
 
51
-
52
  def generate_llm_response(text, model_id="ccibeekeoc42/Llama3.1-8b-base-SFT-2024-11-09"):
53
  full_response = []
54
  try:
@@ -71,9 +69,12 @@ def generate_llm_response(text, model_id="ccibeekeoc42/Llama3.1-8b-base-SFT-2024
71
  if chunk.choices[0].delta.content:
72
  full_response.append(chunk.choices[0].delta.content)
73
  return "".join(full_response)
74
- except InternalServerError as e:
75
- # This error is raised when the GPU is unavailable (e.g. scaling down to 0 after idle)
76
- return "The GPU is currently booting up. Please wait about 10 minutes and try again."
 
 
 
77
 
78
  generate_llm_response("Explain Deep Learning in Igbo")
79
 
 
1
  import os
2
  import openai
 
3
  import torch
4
  from transformers import pipeline
5
 
 
47
 
48
  # return "".join(full_response)
49
 
 
50
  def generate_llm_response(text, model_id="ccibeekeoc42/Llama3.1-8b-base-SFT-2024-11-09"):
51
  full_response = []
52
  try:
 
69
  if chunk.choices[0].delta.content:
70
  full_response.append(chunk.choices[0].delta.content)
71
  return "".join(full_response)
72
+ except Exception as e:
73
+ # If the error has a response with status code 503, assume the GPU is booting up.
74
+ if hasattr(e, 'response') and e.response is not None and e.response.status_code == 503:
75
+ return "The GPU is currently booting up. Please wait about 10 minutes and try again."
76
+ else:
77
+ raise e
78
 
79
  generate_llm_response("Explain Deep Learning in Igbo")
80