Spaces:
Running
Running
Add a simple generations backend
Browse files
app.py
CHANGED
|
@@ -5,8 +5,9 @@ def landing():
|
|
| 5 |
st.title("Writing Tools Prototypes")
|
| 6 |
st.markdown("Click one of the links below to see a prototype in action.")
|
| 7 |
|
| 8 |
-
st.page_link(
|
| 9 |
st.page_link(highlight_page, label="Highlight locations for possible edits", icon="ποΈ")
|
|
|
|
| 10 |
|
| 11 |
st.markdown("*Note*: These services send data to a remote server for processing. The server logs requests. Don't use sensitive or identifiable information on this page.")
|
| 12 |
|
|
@@ -140,14 +141,36 @@ def highlight_edits():
|
|
| 140 |
st.write(pd.DataFrame(spans)[['token', 'token_loss', 'most_likely_token', 'loss_ratio']])
|
| 141 |
st.write("Token loss is the difference between the original token and the most likely token. The loss ratio is the token loss divided by the highest token loss in the document.")
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
rewrite_page = st.Page(rewrite_with_predictions, title="Rewrite with predictions", icon="π")
|
| 145 |
highlight_page = st.Page(highlight_edits, title="Highlight locations for possible edits", icon="ποΈ")
|
|
|
|
| 146 |
|
| 147 |
# Manually specify the sidebar
|
| 148 |
page = st.navigation([
|
| 149 |
st.Page(landing, title="Home", icon="π "),
|
|
|
|
| 150 |
rewrite_page,
|
| 151 |
-
|
| 152 |
])
|
| 153 |
page.run()
|
|
|
|
| 5 |
st.title("Writing Tools Prototypes")
|
| 6 |
st.markdown("Click one of the links below to see a prototype in action.")
|
| 7 |
|
| 8 |
+
st.page_link(rewrite_page, label="Rewrite with predictions", icon="π")
|
| 9 |
st.page_link(highlight_page, label="Highlight locations for possible edits", icon="ποΈ")
|
| 10 |
+
st.page_link(generate_page, label="Generate revisions", icon="π")
|
| 11 |
|
| 12 |
st.markdown("*Note*: These services send data to a remote server for processing. The server logs requests. Don't use sensitive or identifiable information on this page.")
|
| 13 |
|
|
|
|
| 141 |
st.write(pd.DataFrame(spans)[['token', 'token_loss', 'most_likely_token', 'loss_ratio']])
|
| 142 |
st.write("Token loss is the difference between the original token and the most likely token. The loss ratio is the token loss divided by the highest token loss in the document.")
|
| 143 |
|
| 144 |
+
def get_revised_docs(prompt, doc, n):
|
| 145 |
+
response = requests.get("https://tools.kenarnold.org/api/gen_revisions", params=dict(prompt=prompt, doc=doc, n=n))
|
| 146 |
+
return response.json()
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def generate_revisions():
|
| 150 |
+
st.title("Generate revised document")
|
| 151 |
+
|
| 152 |
+
import html
|
| 153 |
+
prompt = get_prompt(include_generation_options=False)
|
| 154 |
+
st.write("Prompt:", prompt)
|
| 155 |
+
doc = st.text_area("Document", "", height=300)
|
| 156 |
+
|
| 157 |
+
revised_docs = get_revised_docs(prompt, doc, n=5)['revised_docs']
|
| 158 |
+
|
| 159 |
+
tabs = st.tabs([f"Draft {i+1}" for i in range(len(revised_docs))])
|
| 160 |
+
for i, tab in enumerate(tabs):
|
| 161 |
+
with tab:
|
| 162 |
+
st.write(revised_docs[i]['doc_text'])
|
| 163 |
+
|
| 164 |
|
| 165 |
rewrite_page = st.Page(rewrite_with_predictions, title="Rewrite with predictions", icon="π")
|
| 166 |
highlight_page = st.Page(highlight_edits, title="Highlight locations for possible edits", icon="ποΈ")
|
| 167 |
+
generate_page = st.Page(generate_revisions, title="Generate revisions", icon="π")
|
| 168 |
|
| 169 |
# Manually specify the sidebar
|
| 170 |
page = st.navigation([
|
| 171 |
st.Page(landing, title="Home", icon="π "),
|
| 172 |
+
highlight_page,
|
| 173 |
rewrite_page,
|
| 174 |
+
generate_page
|
| 175 |
])
|
| 176 |
page.run()
|