Spaces:
Sleeping
Sleeping
Handle errors a bit more gracefully.
Browse files- pages/1_Rewrite.py +5 -1
pages/1_Rewrite.py
CHANGED
@@ -4,13 +4,17 @@ import html
|
|
4 |
|
5 |
|
6 |
prompt = st.text_area("Prompt", "Rewrite this document to be more clear and concise.")
|
7 |
-
doc = st.text_area("Document", "
|
8 |
rewrite_in_progress = st.text_area("Rewrite in progress", key='rewrite_in_progress', value="")
|
9 |
|
|
|
|
|
|
|
10 |
|
11 |
def get_preds_api(prompt, original_doc, rewrite_in_progress, k=5):
|
12 |
import requests
|
13 |
response = requests.get("https://tools.kenarnold.org/api/next_token", params=dict(prompt=prompt, original_doc=original_doc, doc_in_progress=rewrite_in_progress, k=k))
|
|
|
14 |
return response.json()['next_tokens']
|
15 |
|
16 |
tokens = get_preds_api(prompt, doc, rewrite_in_progress)
|
|
|
4 |
|
5 |
|
6 |
prompt = st.text_area("Prompt", "Rewrite this document to be more clear and concise.")
|
7 |
+
doc = st.text_area("Document", "", help="Paste your document here")#"Revolutionize your paradigm-shifting synergy with our cutting-edge quantum cloud solutions!")
|
8 |
rewrite_in_progress = st.text_area("Rewrite in progress", key='rewrite_in_progress', value="")
|
9 |
|
10 |
+
if doc.strip() == "" and rewrite_in_progress.strip() == "":
|
11 |
+
# Allow partial rewrites as a hack to enable autocomplete from the prompt
|
12 |
+
st.stop()
|
13 |
|
14 |
def get_preds_api(prompt, original_doc, rewrite_in_progress, k=5):
|
15 |
import requests
|
16 |
response = requests.get("https://tools.kenarnold.org/api/next_token", params=dict(prompt=prompt, original_doc=original_doc, doc_in_progress=rewrite_in_progress, k=k))
|
17 |
+
response.raise_for_status()
|
18 |
return response.json()['next_tokens']
|
19 |
|
20 |
tokens = get_preds_api(prompt, doc, rewrite_in_progress)
|