Spaces:
Runtime error
Runtime error
Merge branch 'main' of https://huggingface.co/spaces/postbot/autocomplete-emails
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import gradio as gr
|
|
| 5 |
import torch
|
| 6 |
from transformers import pipeline
|
| 7 |
|
| 8 |
-
from utils import postprocess, clear
|
| 9 |
|
| 10 |
logging.basicConfig(
|
| 11 |
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
|
@@ -68,7 +68,9 @@ def generate_text(
|
|
| 68 |
if verbose:
|
| 69 |
logging.info(f"Generated text: {response}")
|
| 70 |
logging.info(f"Generation time: {rt:.2f}s")
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
def get_parser():
|
|
@@ -153,6 +155,8 @@ if __name__ == "__main__":
|
|
| 153 |
label="Generated Result",
|
| 154 |
placeholder="The completed email will appear here",
|
| 155 |
)
|
|
|
|
|
|
|
| 156 |
generate_button = gr.Button(
|
| 157 |
value="Generate!",
|
| 158 |
variant="primary",
|
|
@@ -208,7 +212,7 @@ if __name__ == "__main__":
|
|
| 208 |
no_repeat_ngram_size,
|
| 209 |
length_penalty,
|
| 210 |
],
|
| 211 |
-
outputs=[generated_email],
|
| 212 |
)
|
| 213 |
|
| 214 |
demo.launch(
|
|
|
|
| 5 |
import torch
|
| 6 |
from transformers import pipeline
|
| 7 |
|
| 8 |
+
from utils import postprocess, clear, make_email_link
|
| 9 |
|
| 10 |
logging.basicConfig(
|
| 11 |
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
|
|
|
| 68 |
if verbose:
|
| 69 |
logging.info(f"Generated text: {response}")
|
| 70 |
logging.info(f"Generation time: {rt:.2f}s")
|
| 71 |
+
|
| 72 |
+
formatted_email = postprocess(response)
|
| 73 |
+
return formatted_email, make_email_link(body=formatted_email)
|
| 74 |
|
| 75 |
|
| 76 |
def get_parser():
|
|
|
|
| 155 |
label="Generated Result",
|
| 156 |
placeholder="The completed email will appear here",
|
| 157 |
)
|
| 158 |
+
email_link = gr.HTML("<p><em>A mailto: link will appear here</em></p>")
|
| 159 |
+
|
| 160 |
generate_button = gr.Button(
|
| 161 |
value="Generate!",
|
| 162 |
variant="primary",
|
|
|
|
| 212 |
no_repeat_ngram_size,
|
| 213 |
length_penalty,
|
| 214 |
],
|
| 215 |
+
outputs=[generated_email, email_link],
|
| 216 |
)
|
| 217 |
|
| 218 |
demo.launch(
|
utils.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
|
|
|
|
| 6 |
def postprocess(text: str):
|
| 7 |
"""
|
| 8 |
postprocess - remove common values in scraped dataset
|
|
@@ -40,3 +41,25 @@ def clear(text, verbose=False, **kwargs):
|
|
| 40 |
if verbose:
|
| 41 |
logging.info(f"Clearing text: {text}")
|
| 42 |
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
import logging
|
| 5 |
|
| 6 |
+
|
| 7 |
def postprocess(text: str):
|
| 8 |
"""
|
| 9 |
postprocess - remove common values in scraped dataset
|
|
|
|
| 41 |
if verbose:
|
| 42 |
logging.info(f"Clearing text: {text}")
|
| 43 |
return ""
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def make_email_link(
|
| 47 |
+
subject: str = "Email subject - This was generated by Postbot",
|
| 48 |
+
link_text: str = "click to open in your email client",
|
| 49 |
+
body: str = None,
|
| 50 |
+
):
|
| 51 |
+
"""
|
| 52 |
+
email_link - generate an email link
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
subject (str, optional): the subject of the email. Defaults to "Email subject - This was generated by Postbot".
|
| 56 |
+
link_text (str, optional): the text of the link. Defaults to "click to open in your email client".
|
| 57 |
+
body (_type_, optional): the body of the email. Defaults to None.
|
| 58 |
+
|
| 59 |
+
Returns:
|
| 60 |
+
str: the email link
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
if body is None:
|
| 64 |
+
body = "hmm - no body. replace me"
|
| 65 |
+
return f'<a href="mailto:%20?subject={subject}&body={body}">{link_text}</a>'
|