Spaces:
Running
Running
✨ add better output
Browse filesSigned-off-by: peter szemraj <[email protected]>
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, make_email_link
|
9 |
|
10 |
logging.basicConfig(
|
11 |
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
@@ -68,7 +68,7 @@ def generate_text(
|
|
68 |
logging.info(f"Generation time: {rt:.2f}s")
|
69 |
|
70 |
formatted_email = postprocess(response)
|
71 |
-
return
|
72 |
|
73 |
def load_emailgen_model(model_tag:str):
|
74 |
"""
|
@@ -171,7 +171,7 @@ if __name__ == "__main__":
|
|
171 |
label="Generated Result",
|
172 |
placeholder="The completed email will appear here",
|
173 |
)
|
174 |
-
|
175 |
|
176 |
generate_button = gr.Button(
|
177 |
value="Generate!",
|
@@ -192,13 +192,13 @@ if __name__ == "__main__":
|
|
192 |
'Load Model',
|
193 |
variant='secondary',
|
194 |
)
|
195 |
-
num_beams = gr.Radio(
|
196 |
-
choices=[4, 8, 12, 16],
|
197 |
-
label="Number of Beams",
|
198 |
-
value=8,
|
199 |
-
)
|
200 |
-
with gr.Row():
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
no_repeat_ngram_size = gr.Radio(
|
203 |
choices=[1, 2, 3, 4],
|
204 |
label="no repeat ngram size",
|
@@ -238,7 +238,7 @@ if __name__ == "__main__":
|
|
238 |
no_repeat_ngram_size,
|
239 |
length_penalty,
|
240 |
],
|
241 |
-
outputs=[generated_email,
|
242 |
)
|
243 |
|
244 |
load_model_button.click(
|
|
|
5 |
import torch
|
6 |
from transformers import pipeline
|
7 |
|
8 |
+
from utils import make_mailto_form, postprocess, clear, make_email_link
|
9 |
|
10 |
logging.basicConfig(
|
11 |
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
|
|
68 |
logging.info(f"Generation time: {rt:.2f}s")
|
69 |
|
70 |
formatted_email = postprocess(response)
|
71 |
+
return make_mailto_form(body=formatted_email)
|
72 |
|
73 |
def load_emailgen_model(model_tag:str):
|
74 |
"""
|
|
|
171 |
label="Generated Result",
|
172 |
placeholder="The completed email will appear here",
|
173 |
)
|
174 |
+
email_template = gr.HTML("<p><em>A mailto: link will appear here</em></p>")
|
175 |
|
176 |
generate_button = gr.Button(
|
177 |
value="Generate!",
|
|
|
192 |
'Load Model',
|
193 |
variant='secondary',
|
194 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
|
196 |
+
with gr.Row():
|
197 |
+
num_beams = gr.Radio(
|
198 |
+
choices=[4, 8, 12, 16],
|
199 |
+
label="Number of Beams",
|
200 |
+
value=4,
|
201 |
+
)
|
202 |
no_repeat_ngram_size = gr.Radio(
|
203 |
choices=[1, 2, 3, 4],
|
204 |
label="no repeat ngram size",
|
|
|
238 |
no_repeat_ngram_size,
|
239 |
length_penalty,
|
240 |
],
|
241 |
+
outputs=[generated_email, email_template],
|
242 |
)
|
243 |
|
244 |
load_model_button.click(
|
utils.py
CHANGED
@@ -72,3 +72,69 @@ def make_email_link(
|
|
72 |
body = body.replace("\n", " ")
|
73 |
|
74 |
return f'<a href="mailto:%20?subject={subject}&body={body}">{link_text}</a>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
body = body.replace("\n", " ")
|
73 |
|
74 |
return f'<a href="mailto:%20?subject={subject}&body={body}">{link_text}</a>'
|
75 |
+
|
76 |
+
|
77 |
+
def make_mailto_form(body: str=None, subject: str="This email was generated by Postbot with AI!", cc_email: str="",):
|
78 |
+
"""Returns a mailto link with the given parameters"""
|
79 |
+
|
80 |
+
if body is None:
|
81 |
+
body = "hmm - no body. Replace me or try rerunning the model."
|
82 |
+
|
83 |
+
template = f"""<!DOCTYPE html>
|
84 |
+
<html>
|
85 |
+
<head>
|
86 |
+
<title>Generated Email</title>
|
87 |
+
<style>
|
88 |
+
body {{
|
89 |
+
font-family: sans-serif;
|
90 |
+
font-size: 1.2em;
|
91 |
+
}}
|
92 |
+
.container {{
|
93 |
+
display: flex;
|
94 |
+
flex-direction: column;
|
95 |
+
align-items: center;
|
96 |
+
justify-content: center;
|
97 |
+
height: 100vh;
|
98 |
+
}}
|
99 |
+
.button {{
|
100 |
+
background-color: #6CCEC6;
|
101 |
+
border: none;
|
102 |
+
color: white;
|
103 |
+
padding: 15px 32px;
|
104 |
+
text-align: center;
|
105 |
+
text-decoration: none;
|
106 |
+
display: inline-block;
|
107 |
+
font-size: 16px;
|
108 |
+
margin: 4px 2px;
|
109 |
+
cursor: pointer;
|
110 |
+
value: "Send Email";
|
111 |
+
}}
|
112 |
+
</style>
|
113 |
+
</head>
|
114 |
+
<body>
|
115 |
+
<h1>Adjust and Open in your mail client:</h1>
|
116 |
+
<form action="mailto:" method="get" enctype="text/plain">
|
117 |
+
|
118 |
+
<div>
|
119 |
+
<label for="cc">CC Email:
|
120 |
+
<input type="text" name="cc" id="cc" value="{cc_email}"/>
|
121 |
+
</label>
|
122 |
+
</div>
|
123 |
+
<div>
|
124 |
+
<label for="subject">Subject:
|
125 |
+
<input type="text" name="subject" id="subject" value="{subject}"/>
|
126 |
+
</label>
|
127 |
+
</div>
|
128 |
+
<div>
|
129 |
+
<label>Email Body:</label>
|
130 |
+
<br />
|
131 |
+
<textarea name="body" id="body" rows="12" cols="35">{body}</textarea>
|
132 |
+
</div>
|
133 |
+
<div>
|
134 |
+
<input type="submit" name="submit" value="Open in Email App" class="button"/>
|
135 |
+
</div>
|
136 |
+
</form>
|
137 |
+
</body>
|
138 |
+
</html>"""
|
139 |
+
|
140 |
+
return template
|