Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
3 |
|
4 |
from PIL import Image
|
5 |
import os
|
@@ -34,35 +36,35 @@ def infer(audio, openai_api_key):
|
|
34 |
def try_api(message, openai_api_key):
|
35 |
try:
|
36 |
response = call_api(message, openai_api_key)
|
37 |
-
return response, "no error"
|
38 |
except openai.error.Timeout as e:
|
39 |
#Handle timeout error, e.g. retry or log
|
40 |
print(f"OpenAI API request timed out: {e}")
|
41 |
-
return "oups", f"OpenAI API request timed out: {e}"
|
42 |
except openai.error.APIError as e:
|
43 |
#Handle API error, e.g. retry or log
|
44 |
print(f"OpenAI API returned an API Error: {e}")
|
45 |
-
return "oups", f"OpenAI API returned an API Error: {e}"
|
46 |
except openai.error.APIConnectionError as e:
|
47 |
#Handle connection error, e.g. check network or log
|
48 |
print(f"OpenAI API request failed to connect: {e}")
|
49 |
-
return "oups", f"OpenAI API request failed to connect: {e}"
|
50 |
except openai.error.InvalidRequestError as e:
|
51 |
#Handle invalid request error, e.g. validate parameters or log
|
52 |
print(f"OpenAI API request was invalid: {e}")
|
53 |
-
return "oups", f"OpenAI API request was invalid: {e}"
|
54 |
except openai.error.AuthenticationError as e:
|
55 |
#Handle authentication error, e.g. check credentials or log
|
56 |
print(f"OpenAI API request was not authorized: {e}")
|
57 |
-
return "oups", f"OpenAI API request was not authorized: {e}"
|
58 |
except openai.error.PermissionError as e:
|
59 |
#Handle permission error, e.g. check scope or log
|
60 |
print(f"OpenAI API request was not permitted: {e}")
|
61 |
-
return "oups", f"OpenAI API request was not permitted: {e}"
|
62 |
except openai.error.RateLimitError as e:
|
63 |
#Handle rate limit error, e.g. wait or log
|
64 |
print(f"OpenAI API request exceeded rate limit: {e}")
|
65 |
-
return "oups", f"OpenAI API request exceeded rate limit: {e}"
|
66 |
|
67 |
def call_api(message, openai_api_key):
|
68 |
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
+
import colorama
|
4 |
+
from colorama import Fore
|
5 |
|
6 |
from PIL import Image
|
7 |
import os
|
|
|
36 |
def try_api(message, openai_api_key):
|
37 |
try:
|
38 |
response = call_api(message, openai_api_key)
|
39 |
+
return response, Fore.GREEN + "no error"
|
40 |
except openai.error.Timeout as e:
|
41 |
#Handle timeout error, e.g. retry or log
|
42 |
print(f"OpenAI API request timed out: {e}")
|
43 |
+
return "oups", Fore.RED + f"OpenAI API request timed out: {e}"
|
44 |
except openai.error.APIError as e:
|
45 |
#Handle API error, e.g. retry or log
|
46 |
print(f"OpenAI API returned an API Error: {e}")
|
47 |
+
return "oups", Fore.RED + f"OpenAI API returned an API Error: {e}"
|
48 |
except openai.error.APIConnectionError as e:
|
49 |
#Handle connection error, e.g. check network or log
|
50 |
print(f"OpenAI API request failed to connect: {e}")
|
51 |
+
return "oups", Fore.RED + f"OpenAI API request failed to connect: {e}"
|
52 |
except openai.error.InvalidRequestError as e:
|
53 |
#Handle invalid request error, e.g. validate parameters or log
|
54 |
print(f"OpenAI API request was invalid: {e}")
|
55 |
+
return "oups", Fore.RED + f"OpenAI API request was invalid: {e}"
|
56 |
except openai.error.AuthenticationError as e:
|
57 |
#Handle authentication error, e.g. check credentials or log
|
58 |
print(f"OpenAI API request was not authorized: {e}")
|
59 |
+
return "oups", Fore.RED + f"OpenAI API request was not authorized: {e}"
|
60 |
except openai.error.PermissionError as e:
|
61 |
#Handle permission error, e.g. check scope or log
|
62 |
print(f"OpenAI API request was not permitted: {e}")
|
63 |
+
return "oups", Fore.RED + f"OpenAI API request was not permitted: {e}"
|
64 |
except openai.error.RateLimitError as e:
|
65 |
#Handle rate limit error, e.g. wait or log
|
66 |
print(f"OpenAI API request exceeded rate limit: {e}")
|
67 |
+
return "oups", Fore.RED + f"OpenAI API request exceeded rate limit: {e}"
|
68 |
|
69 |
def call_api(message, openai_api_key):
|
70 |
|