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