Spaces:
Running
Running
WIP predictive-text-mode
Browse files- rewrite.py +26 -0
rewrite.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
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", "This is a document that I would like to have rewritten to be more concise.")
|
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)
|
17 |
+
|
18 |
+
def append_token(word):
|
19 |
+
st.session_state['rewrite_in_progress'] = (
|
20 |
+
st.session_state['rewrite_in_progress'] + word
|
21 |
+
)
|
22 |
+
|
23 |
+
for col, token in zip(st.columns(len(tokens)), tokens):
|
24 |
+
with col:
|
25 |
+
st.button(token, on_click=append_token, args=(token,))
|
26 |
+
|