adriiita commited on
Commit
41f0774
·
verified ·
1 Parent(s): dce4fee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+ client = Groq(
6
+ api_key=os.environ.get("GROQ_API_KEY"),
7
+ )
8
+
9
+ def structure_info(info):
10
+ prompt = f"Please just structure and summarize the following information about a person or company and just simply give the result directly: {info}"
11
+ chat_completion = client.chat.completions.create(
12
+ messages=[
13
+ {
14
+ "role": "user",
15
+ "content": prompt,
16
+ }
17
+ ],
18
+ model="llama-3.1-8b-instant",
19
+ )
20
+ return chat_completion.choices[0].message.content
21
+
22
+ def generate_email(sender_name, email_subject, recipient, structured_info):
23
+ prompt = f"""I'm {sender_name}. Write a personalized email to {recipient} about {email_subject} which will be personalized to {recipient} by understanding {structured_info}. The email should introduce the sender, briefly describe the subject, and highlight its key benefits or relevance to the recipient's profile or company."""
24
+
25
+ chat_completion = client.chat.completions.create(
26
+ messages=[
27
+ {
28
+ "role": "user",
29
+ "content": prompt,
30
+ }
31
+ ],
32
+ model="llama-3.1-8b-instant",
33
+ )
34
+ return chat_completion.choices[0].message.content
35
+
36
+ def email_interface(name, subject, recipient, recipient_info):
37
+ structured_info = structure_info(recipient_info)
38
+ return generate_email(name, subject, recipient, structured_info)
39
+
40
+ demo = gr.Interface(
41
+ fn=email_interface,
42
+ inputs=[
43
+ gr.Textbox(label="Your Name"),
44
+ gr.Textbox(label="Email Subject"),
45
+ gr.Textbox(label="Recipient Name/Company"),
46
+ gr.Textbox(label="Recipient Information (e.g., Name, Motive, What they do)")
47
+ ],
48
+ outputs="text",
49
+ title="EmailGenie",
50
+ description="Generate a personalized email based on recipient information",
51
+ examples=[
52
+ ["John Doe", "Collaboration on AI Project", "TechCorp", "TechCorp is a leading AI research company focused on developing cutting-edge machine learning algorithms."],
53
+ ["Jane Smith", "AI Workshop Invitation", "Dr. Alex Johnson", "Dr. Alex Johnson is a renowned AI researcher specializing in natural language processing at Stanford University."]
54
+ ]
55
+ )
56
+
57
+ if __name__ == "__main__":
58
+ demo.launch()