siddhartharya commited on
Commit
2259d36
·
verified ·
1 Parent(s): 3bc7dd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
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
- chat_completion = client.chat.completions.create(
17
- messages=[
18
- {"role": "system", "content": SYSTEM_PROMPT},
19
- {"role": "user", "content": prompt}
20
- ],
21
- model="mixtral-8x7b-32768",
22
- temperature=0.5,
23
- max_tokens=500,
24
- )
25
-
26
- return chat_completion.choices[0].message.content
 
 
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