kcarnold commited on
Commit
8c99b80
·
1 Parent(s): dc6136e

Side by side

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -36,25 +36,30 @@ def get_prompt(default="Rewrite this document to be more clear and concise."):
36
  return prompt
37
 
38
 
 
 
 
 
 
 
 
39
  def rewrite_with_predictions():
40
  st.title("Rewrite with Predictive Text")
41
 
42
  prompt = get_prompt()
43
  st.write("Prompt:", prompt)
44
 
45
- doc = st.text_area("Document", "", placeholder="Paste your document here.", height=300)
46
- st.button("Update document")
47
- rewrite_in_progress = st.text_area("Rewrite in progress", key='rewrite_in_progress', value="", placeholder="Clicking the buttons below will update this field. You can also edit it directly; press Ctrl+Enter to apply changes.", height=300)
 
 
 
48
 
49
  if doc.strip() == "" and rewrite_in_progress.strip() == "":
50
  # Allow partial rewrites as a hack to enable autocomplete from the prompt
51
  st.stop()
52
 
53
- def get_preds_api(prompt, original_doc, rewrite_in_progress, k=5):
54
- 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))
55
- response.raise_for_status()
56
- return response.json()['next_tokens']
57
-
58
  tokens = get_preds_api(prompt, doc, rewrite_in_progress)
59
 
60
  def append_token(word):
 
36
  return prompt
37
 
38
 
39
+ @st.cache_data
40
+ def get_preds_api(prompt, original_doc, rewrite_in_progress, k=5):
41
+ 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))
42
+ response.raise_for_status()
43
+ return response.json()['next_tokens']
44
+
45
+
46
  def rewrite_with_predictions():
47
  st.title("Rewrite with Predictive Text")
48
 
49
  prompt = get_prompt()
50
  st.write("Prompt:", prompt)
51
 
52
+ cols = st.columns(2)
53
+ with cols[0]:
54
+ doc = st.text_area("Document", "", placeholder="Paste your document here.", height=300)
55
+ st.button("Update document")
56
+ with cols[1]:
57
+ rewrite_in_progress = st.text_area("Rewrite in progress", key='rewrite_in_progress', value="", placeholder="Clicking the buttons below will update this field. You can also edit it directly; press Ctrl+Enter to apply changes.", height=300)
58
 
59
  if doc.strip() == "" and rewrite_in_progress.strip() == "":
60
  # Allow partial rewrites as a hack to enable autocomplete from the prompt
61
  st.stop()
62
 
 
 
 
 
 
63
  tokens = get_preds_api(prompt, doc, rewrite_in_progress)
64
 
65
  def append_token(word):