Spaces:
Sleeping
Sleeping
from groq import Groq | |
import os | |
from dotenv import load_dotenv | |
load_dotenv() | |
api = os.getenv("groq_api_key") | |
client = Groq(api_key=api,) | |
complaint_email=""" | |
Subject: Urgent: Immediate Attention Required - Extremely Disappointed with Recent Service | |
Dear Neeta, | |
I am writing to express my frustration and profound disappointment regarding the service I have recently received from Mahalaxmi Incorporation. Despite repeated efforts on my part to address these issues, I have been met with delays, lack of communication, and unfulfilled promises—behavior that is, frankly, unacceptable. | |
To date, my recent order #12345, placed on 22nd May, has been delayed three times without any valid explanation or updates. I have reached out to your team multiple times, only to be met with conflicting information and assurances that the problem would be resolved, yet no action has been taken. This not only reflects poorly on your organization but has also resulted insignificant disruptions to my schedule and financial loss. | |
I demand that this matter be resolved promptly and expect a detailed response outlining the immediate steps you will take to address this issue. It is critical that I receive a clear timeline for resolution by the end of the week. | |
Failing this, I will be left with no choice but to escalate my complaint to higher authorities and explore alternative measures. | |
I look forward to your immediate response. | |
Sincerely, | |
Yatharth | |
""" | |
professional_email=""" | |
Subject: Follow-up on Customer Segmentation Project and Upcoming Milestones | |
Dear Dr. Smith, | |
I hope you’re doing well. I wanted to provide an update on our Customer Segmentation project following our meeting on October 20. Since then, we’ve made significant progress: data gathering and initial preprocessing from the past two fiscal years are complete, and we’ve developed preliminary segmentation models focusing on key demographic and behavioral metrics. The analytics team is currently reviewing these early findings, and initial results show promising insights for identifying high-potential customer clusters. | |
To stay on course, we’re aiming to finalize data validation by October 31, ensuring a clean and standardized dataset. We plan to refine and test the segmentation models with the analytics team’s input, targeting completion by November 10. Our goal is to present a summary of findings and a preliminary marketing action plan at the stakeholder meeting scheduled for November 15. | |
To further enrich our analysis, access to recent customer survey data would be invaluable, particularly for enhancing behavioral insights. Any feedback you might have on the preliminary clusters or guidance on specific aspects to emphasize would also be much appreciated. | |
Thank you for your continued support and collaboration. Please let me know if you’d like to discuss any aspect of this further or if there are additional resources you recommend for this phase of the project. | |
Best regards, | |
Emily Johnson | |
Senior Data Analyst | |
Marketing Analytics Department | |
Innovate Solutions Inc. | |
emily.johnson@innovatesolutions.com | |
(555) 123-4567 | |
""" | |
informal_email=""" | |
Subject: Let’s Plan a Hangout Soon! | |
Hey Ankit, | |
Hope everything’s good with you! It’s been way too long since we last hung out, so I thought we should plan a day out soon. I’ve got a few ideas, but of course, I’m open to whatever sounds fun to you. Here’s what I was thinking: | |
Bowling Night: We could hit the lanes, play a few rounds, and see who’s got the best moves (or maybe the worst—it’s all part of the fun). | |
Park Picnic: We could do a relaxed potluck-style picnic, bring a few snacks, and just chill outside. Maybe bring some music, cards, or a frisbee if we’re up for it. | |
Escape Room: If we’re feeling adventurous, we could try one of those escape rooms. Thought it’d be fun to team up and see how we handle the challenge (and hopefully escape!). | |
Let me know which of these sounds good, or feel free to throw out any other ideas you have! Also, let me know your availability over the next couple of weekends so we can lock in a day that works for both of us. | |
Looking forward to a fun hangout—can’t wait to catch up! | |
Best, | |
Samar | |
""" | |
def generate_message(sample_email,user_text,relation): | |
if(sample_email=="Professional"): | |
sample_email=professional_email | |
elif(sample_email=="Informal"): | |
sample_email=informal_email | |
else: | |
sample_email=complaint_email | |
message=[{"role": "system", "content": "You are an email writing assistant.You have been give one sample email.Learn from that email ,the tone in which the email is written.Now format the text user provided you to generate an email in the tone of the sample email.While writing keep in mind the relation between user and reciever and format the email accordingly also.Also you can make changes to it as per the context but keep the tone same.Do not mention about the sample email in response text.Just give the mail and nothing else."}, | |
{"role": "user","content": "Sample email:\n"+sample_email+"\n \n User provided text:\n"+user_text+"\n \n User says that user and recipient are realted as:"+relation}] | |
return message | |
def response(sample_email,user_text,relation): | |
message=generate_message(sample_email,user_text,relation) | |
chat_completion=client.chat.completions.create( | |
messages=message, | |
model="llama3-70b-8192", | |
) | |
return chat_completion.choices[0].message.content | |
import gradio as gr | |
demo = gr.Interface( | |
fn=response, | |
inputs=[gr.Dropdown(["Professional", "Informal", "Complaint"], label="Tone"), gr.Textbox(label="Enter the text"),gr.Textbox(label="How are you and the recipient related")], | |
outputs=gr.Textbox(label="Here is your email"), | |
title="Email Assistant" | |
) | |
demo.launch(share="True") |