Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,12 +10,14 @@ import time
|
|
| 10 |
|
| 11 |
# Environment variables
|
| 12 |
openai_key = os.getenv("OPENAI_KEY")
|
|
|
|
|
|
|
|
|
|
| 13 |
if not openai_key:
|
| 14 |
raise gr.Error("OPENAI_KEY not set")
|
| 15 |
-
|
| 16 |
client = OpenAI(api_key=openai_key)
|
| 17 |
|
| 18 |
-
|
| 19 |
g = Github(github_key) if github_key else None
|
| 20 |
|
| 21 |
# Repo name, if you want to save to a github repository change RepositoryName to your repo name, name must be under quotations
|
|
@@ -57,6 +59,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
|
|
| 57 |
|
| 58 |
# Create a GitHub repository file to store the Data
|
| 59 |
if g:
|
|
|
|
| 60 |
try:
|
| 61 |
repo = g.get_user().get_repo(REPO_NAME)
|
| 62 |
filename = f"{new_id}.txt"
|
|
@@ -113,6 +116,8 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
|
|
| 113 |
# Catch invalid or expired API keys and show a clean error message
|
| 114 |
if "401" in error_msg or "invalid_api_key" in error_msg or "incorrect api key" in error_msg:
|
| 115 |
raise gr.Error("Error: The OpenAI API Key provided is invalid or expired.")
|
|
|
|
|
|
|
| 116 |
else:
|
| 117 |
raise gr.Error(f"Error: {str(e)}")
|
| 118 |
|
|
@@ -147,7 +152,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css="""footer {display:none !import
|
|
| 147 |
# User Interface components
|
| 148 |
Chatbot = gr.Chatbot(
|
| 149 |
type="messages",
|
| 150 |
-
label="Anonymous User"
|
| 151 |
)
|
| 152 |
|
| 153 |
txt = gr.Textbox(
|
|
|
|
| 10 |
|
| 11 |
# Environment variables
|
| 12 |
openai_key = os.getenv("OPENAI_KEY")
|
| 13 |
+
github_key = os.getenv("GITHUB_KEY")
|
| 14 |
+
|
| 15 |
+
# Check openai key
|
| 16 |
if not openai_key:
|
| 17 |
raise gr.Error("OPENAI_KEY not set")
|
|
|
|
| 18 |
client = OpenAI(api_key=openai_key)
|
| 19 |
|
| 20 |
+
# Check Github key
|
| 21 |
g = Github(github_key) if github_key else None
|
| 22 |
|
| 23 |
# Repo name, if you want to save to a github repository change RepositoryName to your repo name, name must be under quotations
|
|
|
|
| 59 |
|
| 60 |
# Create a GitHub repository file to store the Data
|
| 61 |
if g:
|
| 62 |
+
# Try to create repository
|
| 63 |
try:
|
| 64 |
repo = g.get_user().get_repo(REPO_NAME)
|
| 65 |
filename = f"{new_id}.txt"
|
|
|
|
| 116 |
# Catch invalid or expired API keys and show a clean error message
|
| 117 |
if "401" in error_msg or "invalid_api_key" in error_msg or "incorrect api key" in error_msg:
|
| 118 |
raise gr.Error("Error: The OpenAI API Key provided is invalid or expired.")
|
| 119 |
+
elif "ascii" in error_msg:
|
| 120 |
+
raise gr.Error("Error: The OpenAI API Key was set incorrectly")
|
| 121 |
else:
|
| 122 |
raise gr.Error(f"Error: {str(e)}")
|
| 123 |
|
|
|
|
| 152 |
# User Interface components
|
| 153 |
Chatbot = gr.Chatbot(
|
| 154 |
type="messages",
|
| 155 |
+
label="Anonymous User" # Participant User Name
|
| 156 |
)
|
| 157 |
|
| 158 |
txt = gr.Textbox(
|