File size: 2,226 Bytes
e8d7b65
baa7209
 
 
 
 
 
e8d7b65
baa7209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ef24fb
 
 
 
 
 
 
baa7209
 
 
 
2ef24fb
baa7209
 
 
 
 
 
 
 
2ef24fb
 
 
 
 
 
 
 
 
 
 
 
 
 
baa7209
 
 
 
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
# from dotenv import load_dotenv
import os
import gradio as gr

from groq import Groq

# # Load environment variables from .env file
# load_dotenv()

client = Groq(
    api_key=os.environ.get("GROQ_API_KEY"),
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Tell me a funny joke",
        }
    ],
    model="llama3-8b-8192",
)

print(chat_completion.choices[0].message.content)

def chat_with_groq(sender_name, receiver_name, about_receiver, project_name, project_details, key_benefits, additional_info=None):
    # Create a more personalized message by including sender, receiver, and additional info
    full_message = (
        f"Compose a personalized email to {receiver_name}, starting with a friendly greeting which include details about the receiver from {about_receiver}. Briefly introduce yourself {sender_name} and express your enthusiasm for sharing details about {project_name}. Describe the {project_details} in a way that highlights its innovative aspects and its potential impact on {receiver_name} or their business. Clearly outline the {key_benefits} of the project, emphasizing how it can address specific challenges or goals that {receiver_name} might have. End the email by inviting {sender_name} to discuss the project further, and provide your contact information [email protected] for follow-up."
        
)

    chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": full_message,
        }
    ],
    model="llama3-8b-8192",
    )
    return chat_completion.choices[0].message.content


#add UI
iface = gr.Interface(
    fn=chat_with_groq,
    inputs=[
        gr.Textbox(label="Sender Name"),
        gr.Textbox(label="Receiver Name"),
        gr.Textbox(label="About Receiver"),
        gr.Textbox(label="Project Name"),
        gr.Textbox(label="Project Details"),
        gr.Textbox(label="Key Benefits")
        
    ],
    outputs=gr.Textbox(label="Chatbot Response"),
    title="Sonjil's Personalized ChatBot",
    description="Send a personalized email using Sonjil's Groq-powered chatbot"
)

if __name__=="__main__":
    iface.launch()