Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import os
|
|
| 3 |
import openai
|
| 4 |
import requests
|
| 5 |
import json
|
|
|
|
|
|
|
| 6 |
|
| 7 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 8 |
|
|
@@ -15,12 +17,13 @@ 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 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
except requests.exceptions.RequestException as e:
|
| 25 |
print(f"An error occurred while downloading prompt templates: {e}")
|
| 26 |
return
|
|
@@ -28,7 +31,6 @@ def download_prompt_templates():
|
|
| 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 |
|
|
|
|
| 3 |
import openai
|
| 4 |
import requests
|
| 5 |
import json
|
| 6 |
+
import csv
|
| 7 |
+
|
| 8 |
|
| 9 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 10 |
|
|
|
|
| 17 |
url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"
|
| 18 |
try:
|
| 19 |
response = requests.get(url)
|
| 20 |
+
reader = csv.reader(response.text.splitlines())
|
| 21 |
+
next(reader) # skip the header row
|
| 22 |
+
for row in reader:
|
| 23 |
+
if len(row) >= 2:
|
| 24 |
+
act = row[0].strip('"')
|
| 25 |
+
prompt = row[1].strip('"')
|
| 26 |
+
prompt_templates[act] = prompt
|
| 27 |
except requests.exceptions.RequestException as e:
|
| 28 |
print(f"An error occurred while downloading prompt templates: {e}")
|
| 29 |
return
|
|
|
|
| 31 |
choices = list(prompt_templates.keys())
|
| 32 |
return gr.update(value=choices[0], choices=choices)
|
| 33 |
|
|
|
|
| 34 |
def on_token_change(user_token):
|
| 35 |
openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
|
| 36 |
|