Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,17 +13,22 @@ def get_empty_state():
|
|
| 13 |
|
| 14 |
def download_prompt_templates():
|
| 15 |
url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
choices = list(prompt_templates.keys())
|
| 25 |
return gr.update(value=choices[0], choices=choices)
|
| 26 |
|
|
|
|
| 27 |
def on_token_change(user_token):
|
| 28 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
| 29 |
|
|
|
|
| 13 |
|
| 14 |
def download_prompt_templates():
|
| 15 |
url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"
|
| 16 |
+
try:
|
| 17 |
+
response = requests.get(url)
|
| 18 |
+
for line in response.text.splitlines()[1:]:
|
| 19 |
+
try:
|
| 20 |
+
act, prompt = line.split('","')
|
| 21 |
+
prompt_templates[act.replace('"', '')] = prompt.replace('"', '')
|
| 22 |
+
except ValueError:
|
| 23 |
+
print(f"Error occurred while splitting line: {line}")
|
| 24 |
+
except requests.exceptions.RequestException as e:
|
| 25 |
+
print(f"An error occurred while downloading prompt templates: {e}")
|
| 26 |
+
return
|
| 27 |
|
| 28 |
choices = list(prompt_templates.keys())
|
| 29 |
return gr.update(value=choices[0], choices=choices)
|
| 30 |
|
| 31 |
+
|
| 32 |
def on_token_change(user_token):
|
| 33 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
| 34 |
|