Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -83,7 +83,7 @@ def get_music(pat, prompt, track_duration, gen_intensity, gen_mode):
|
|
83 |
headers = {
|
84 |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7; rv:93.0) Gecko/20100101 Firefox/93.0'}
|
85 |
|
86 |
-
retries =
|
87 |
delay = 5 # in seconds
|
88 |
while retries > 0:
|
89 |
response = requests.get(track, headers=headers)
|
@@ -140,31 +140,31 @@ def try_api(message, openai_api_key):
|
|
140 |
return response, "<span class='openai_clear'>no error</span>"
|
141 |
except openai.error.Timeout as e:
|
142 |
#Handle timeout error, e.g. retry or log
|
143 |
-
print(f"OpenAI API request timed out: {e}")
|
144 |
return "oups", f"<span class='openai_error'>OpenAI API request timed out: <br />{e}</span>"
|
145 |
except openai.error.APIError as e:
|
146 |
#Handle API error, e.g. retry or log
|
147 |
-
print(f"OpenAI API returned an API Error: {e}")
|
148 |
return "oups", f"<span class='openai_error'>OpenAI API returned an API Error: <br />{e}</span>"
|
149 |
except openai.error.APIConnectionError as e:
|
150 |
#Handle connection error, e.g. check network or log
|
151 |
-
print(f"OpenAI API request failed to connect: {e}")
|
152 |
return "oups", f"<span class='openai_error'>OpenAI API request failed to connect: <br />{e}</span>"
|
153 |
except openai.error.InvalidRequestError as e:
|
154 |
#Handle invalid request error, e.g. validate parameters or log
|
155 |
-
print(f"OpenAI API request was invalid: {e}")
|
156 |
return "oups", f"<span class='openai_error'>OpenAI API request was invalid: <br />{e}</span>"
|
157 |
except openai.error.AuthenticationError as e:
|
158 |
#Handle authentication error, e.g. check credentials or log
|
159 |
-
print(f"OpenAI API request was not authorized: {e}")
|
160 |
return "oups", f"<span class='openai_error'>OpenAI API request was not authorized: <br />{e}</span>"
|
161 |
except openai.error.PermissionError as e:
|
162 |
#Handle permission error, e.g. check scope or log
|
163 |
-
print(f"OpenAI API request was not permitted: {e}")
|
164 |
return "oups", f"<span class='openai_error'>OpenAI API request was not permitted: <br />{e}</span>"
|
165 |
except openai.error.RateLimitError as e:
|
166 |
#Handle rate limit error, e.g. wait or log
|
167 |
-
print(f"OpenAI API request exceeded rate limit: {e}")
|
168 |
return "oups", f"<span class='openai_error'>OpenAI API request exceeded rate limit: <br />{e}</span>"
|
169 |
|
170 |
def call_api(message, openai_api_key):
|
|
|
83 |
headers = {
|
84 |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7; rv:93.0) Gecko/20100101 Firefox/93.0'}
|
85 |
|
86 |
+
retries = 5
|
87 |
delay = 5 # in seconds
|
88 |
while retries > 0:
|
89 |
response = requests.get(track, headers=headers)
|
|
|
140 |
return response, "<span class='openai_clear'>no error</span>"
|
141 |
except openai.error.Timeout as e:
|
142 |
#Handle timeout error, e.g. retry or log
|
143 |
+
#print(f"OpenAI API request timed out: {e}")
|
144 |
return "oups", f"<span class='openai_error'>OpenAI API request timed out: <br />{e}</span>"
|
145 |
except openai.error.APIError as e:
|
146 |
#Handle API error, e.g. retry or log
|
147 |
+
#print(f"OpenAI API returned an API Error: {e}")
|
148 |
return "oups", f"<span class='openai_error'>OpenAI API returned an API Error: <br />{e}</span>"
|
149 |
except openai.error.APIConnectionError as e:
|
150 |
#Handle connection error, e.g. check network or log
|
151 |
+
#print(f"OpenAI API request failed to connect: {e}")
|
152 |
return "oups", f"<span class='openai_error'>OpenAI API request failed to connect: <br />{e}</span>"
|
153 |
except openai.error.InvalidRequestError as e:
|
154 |
#Handle invalid request error, e.g. validate parameters or log
|
155 |
+
#print(f"OpenAI API request was invalid: {e}")
|
156 |
return "oups", f"<span class='openai_error'>OpenAI API request was invalid: <br />{e}</span>"
|
157 |
except openai.error.AuthenticationError as e:
|
158 |
#Handle authentication error, e.g. check credentials or log
|
159 |
+
#print(f"OpenAI API request was not authorized: {e}")
|
160 |
return "oups", f"<span class='openai_error'>OpenAI API request was not authorized: <br />{e}</span>"
|
161 |
except openai.error.PermissionError as e:
|
162 |
#Handle permission error, e.g. check scope or log
|
163 |
+
#print(f"OpenAI API request was not permitted: {e}")
|
164 |
return "oups", f"<span class='openai_error'>OpenAI API request was not permitted: <br />{e}</span>"
|
165 |
except openai.error.RateLimitError as e:
|
166 |
#Handle rate limit error, e.g. wait or log
|
167 |
+
#print(f"OpenAI API request exceeded rate limit: {e}")
|
168 |
return "oups", f"<span class='openai_error'>OpenAI API request exceeded rate limit: <br />{e}</span>"
|
169 |
|
170 |
def call_api(message, openai_api_key):
|