Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,29 +13,33 @@ You are an AI assistant that generates personalized emails. The recipient is Joh
|
|
13 |
def generate_email(name, project, key_benefits):
|
14 |
prompt = f"Generate an email to the person described in the system prompt. The email should be from {name}, about the project '{project}', and highlight the following key benefits: {key_benefits}"
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
# Create Gradio interface
|
29 |
iface = gr.Interface(
|
30 |
fn=generate_email,
|
31 |
inputs=[
|
32 |
-
gr.Textbox(label="Your Name"),
|
33 |
-
gr.Textbox(label="Project Name"),
|
34 |
-
gr.Textbox(label="Key Benefits")
|
35 |
],
|
36 |
outputs=gr.Textbox(label="Generated Email"),
|
37 |
title="Email Generator",
|
38 |
-
description="Generate a personalized email based on the given inputs."
|
|
|
|
|
39 |
)
|
40 |
|
41 |
# Launch the app
|
|
|
13 |
def generate_email(name, project, key_benefits):
|
14 |
prompt = f"Generate an email to the person described in the system prompt. The email should be from {name}, about the project '{project}', and highlight the following key benefits: {key_benefits}"
|
15 |
|
16 |
+
try:
|
17 |
+
chat_completion = client.chat.completions.create(
|
18 |
+
messages=[
|
19 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
20 |
+
{"role": "user", "content": prompt}
|
21 |
+
],
|
22 |
+
model="mixtral-8x7b-32768",
|
23 |
+
temperature=0.5,
|
24 |
+
max_tokens=500,
|
25 |
+
)
|
26 |
+
return chat_completion.choices[0].message.content
|
27 |
+
except Exception as e:
|
28 |
+
return f"An error occurred: {str(e)}"
|
29 |
|
30 |
# Create Gradio interface
|
31 |
iface = gr.Interface(
|
32 |
fn=generate_email,
|
33 |
inputs=[
|
34 |
+
gr.Textbox(label="Your Name", placeholder="Enter your name"),
|
35 |
+
gr.Textbox(label="Project Name", placeholder="Enter the project name"),
|
36 |
+
gr.Textbox(label="Key Benefits", placeholder="List key benefits, separated by commas")
|
37 |
],
|
38 |
outputs=gr.Textbox(label="Generated Email"),
|
39 |
title="Email Generator",
|
40 |
+
description="Generate a personalized email based on the given inputs.",
|
41 |
+
theme="default",
|
42 |
+
css=".gradio-container {max-width: 800px; margin: auto;}"
|
43 |
)
|
44 |
|
45 |
# Launch the app
|