Spaces:
Sleeping
Sleeping
File size: 1,412 Bytes
1051c7d 16aec6d 1051c7d 970f795 1051c7d 16aec6d 970f795 1051c7d 16aec6d 1051c7d 16aec6d 1051c7d 16aec6d 1051c7d 16aec6d 1051c7d 16aec6d 970f795 1051c7d 16aec6d 970f795 16aec6d 1051c7d |
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 |
import os
import gradio as gr
from groq import Groq
# Initialize Groq client
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
# System prompt with recipient's profile
SYSTEM_PROMPT = """
You are an AI assistant that generates personalized emails. The recipient is John Doe, a 45-year-old marketing executive at a tech company. He is interested in innovative marketing strategies and has a busy schedule.
"""
def generate_email(name, project, key_benefits):
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}"
chat_completion = client.chat.completions.create(
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": prompt}
],
model="mixtral-8x7b-32768",
temperature=0.5,
max_tokens=500,
)
return chat_completion.choices[0].message.content
# Create Gradio interface
iface = gr.Interface(
fn=generate_email,
inputs=[
gr.Textbox(label="Your Name"),
gr.Textbox(label="Project Name"),
gr.Textbox(label="Key Benefits")
],
outputs=gr.Textbox(label="Generated Email"),
title="Email Generator",
description="Generate a personalized email based on the given inputs."
)
# Launch the app
iface.launch() |