Spaces:
Runtime error
Runtime error
Namantaneja
commited on
Commit
•
cb349f8
1
Parent(s):
9dc3c4a
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import groq
|
3 |
+
import os
|
4 |
+
from typing import List, Tuple
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
# Initialize the Groq client
|
9 |
+
client = groq.Groq(api_key=os.getenv("GROQ_API_KEY"))
|
10 |
+
|
11 |
+
# Initialize an empty list to store chat history
|
12 |
+
chat_history = []
|
13 |
+
|
14 |
+
def generate_email(name: str, job_title: str, company_name: str, purpose: str, tone: str, length: str, jargon: str):
|
15 |
+
prompt = f"""Write a cold email with the following details:
|
16 |
+
Recipient: {name}, {job_title} at {company_name}
|
17 |
+
Purpose: {purpose}
|
18 |
+
Tone: {tone}
|
19 |
+
Length: {length}
|
20 |
+
Include industry jargon: {jargon}
|
21 |
+
|
22 |
+
Please write the email now:"""
|
23 |
+
|
24 |
+
# Add user input to chat history
|
25 |
+
chat_history.append(("User", prompt))
|
26 |
+
|
27 |
+
# Generate email using Groq API
|
28 |
+
chat_completion = client.chat.completions.create(
|
29 |
+
messages=[
|
30 |
+
{
|
31 |
+
"role": "system",
|
32 |
+
"content": "You are an expert cold email writer. Your task is to write personalized and effective cold emails based on the given information. The email should always have a clear and concise subject line."
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"role": "user",
|
36 |
+
"content": prompt
|
37 |
+
}
|
38 |
+
],
|
39 |
+
model="llama-3.1-8b-instant",
|
40 |
+
max_tokens=1000,
|
41 |
+
)
|
42 |
+
|
43 |
+
# Extract the generated email
|
44 |
+
generated_email = chat_completion.choices[0].message.content
|
45 |
+
|
46 |
+
# Add generated email to chat history
|
47 |
+
chat_history.append(("Assistant", generated_email))
|
48 |
+
|
49 |
+
return generated_email
|
50 |
+
|
51 |
+
# Define the Gradio interface
|
52 |
+
with gr.Blocks() as app:
|
53 |
+
gr.Markdown("# Cold Email Generator")
|
54 |
+
|
55 |
+
with gr.Row():
|
56 |
+
with gr.Column():
|
57 |
+
name = gr.Textbox(label="Recipient Name")
|
58 |
+
job_title = gr.Textbox(label="Job Title")
|
59 |
+
company_name = gr.Textbox(label="Company Name")
|
60 |
+
|
61 |
+
with gr.Column():
|
62 |
+
purpose = gr.Textbox(label="Purpose of the Email")
|
63 |
+
tone = gr.Radio(["Formal", "Casual", "Friendly"], label="Desired Tone")
|
64 |
+
length = gr.Radio(["Short", "Medium", "Long"], label="Preferred Email Length")
|
65 |
+
jargon = gr.Radio(["Yes", "No"], label="Include Industry-Specific Jargon")
|
66 |
+
|
67 |
+
generate_button = gr.Button("Generate Email")
|
68 |
+
output = gr.Textbox(label="Generated Email")
|
69 |
+
|
70 |
+
generate_button.click(
|
71 |
+
generate_email,
|
72 |
+
inputs=[name, job_title, company_name, purpose, tone, length, jargon],
|
73 |
+
outputs=[output]
|
74 |
+
)
|
75 |
+
|
76 |
+
app.launch()
|