import os import gradio as gr from groq import Groq client = Groq( api_key=os.environ.get("GROQ_API_KEY"), ) def structure_info(info): prompt = f"Please just structure and summarize the following information about a person or company and just simply give the result directly: {info}" chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": prompt, } ], model="llama-3.1-8b-instant", ) return chat_completion.choices[0].message.content def generate_email(sender_name, email_subject, recipient, structured_info): 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.""" chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": prompt, } ], model="llama-3.1-8b-instant", ) return chat_completion.choices[0].message.content def email_interface(name, subject, recipient, recipient_info): structured_info = structure_info(recipient_info) return generate_email(name, subject, recipient, structured_info) demo = gr.Interface( fn=email_interface, inputs=[ gr.Textbox(label="Your Name"), gr.Textbox(label="Email Subject"), gr.Textbox(label="Recipient Name/Company"), gr.Textbox(label="Recipient Information (e.g., Name, Motive, What they do)") ], outputs="text", title="EmailGenie", description="Generate a personalized email based on recipient information", examples=[ ["John Doe", "Collaboration on AI Project", "TechCorp", "TechCorp is a leading AI research company focused on developing cutting-edge machine learning algorithms."], ["Jane Smith", "AI Workshop Invitation", "Dr. Alex Johnson", "Dr. Alex Johnson is a renowned AI researcher specializing in natural language processing at Stanford University."] ] ) if __name__ == "__main__": demo.launch()