File size: 2,885 Bytes
cac9eab
24b72ba
7409805
24b72ba
68833e7
8c614a4
68833e7
868be87
6ff8f56
 
 
868be87
 
 
b3fd8d6
6ff8f56
 
 
 
 
868be87
9ebb42b
868be87
68833e7
6ff8f56
b3fd8d6
faf6738
b3fd8d6
 
 
 
 
 
51ff7fb
 
6ff8f56
 
 
 
 
 
 
 
 
51ff7fb
830f5f1
 
 
6ff8f56
868be87
6ff8f56
 
b3fd8d6
 
6ff8f56
b3fd8d6
6ff8f56
868be87
b3fd8d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
868be87
6ff8f56
 
868be87
6ff8f56
b3fd8d6
830f5f1
 
 
6ff8f56
868be87
830f5f1
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
77
78
79
80
81
82
83
84
85
86
import streamlit as st
import openai
import os

# Ensure your OpenAI API key is set in your environment variables
openai.api_key = os.environ["OPENAI_API_KEY"]

# Initial system message setup for the emoji adder
initial_messages = [{
    "role": "system",
    "content": """
    You are an assistant that adds appropriate emojis to a given text. 
    Analyze the content for tone, context, and meaning, and then insert emojis 
    in a way that enhances the message without overwhelming it. 
    The style of emoji usage will depend on the user's preferences for tone, density, and placement.
    """
}]

def call_openai_api(messages):
    return openai.ChatCompletion.create(
        model="gpt-4",
        messages=messages,
        max_tokens=500  # Adjust based on the expected length of emoji-enhanced output
    )

def CustomChatGPT(text, tone, density, placement, messages):
    query = f"""
    Enhance the following text by adding emojis based on these preferences:
    - Tone: {tone}
    - Density: {density}
    - Placement: {placement}
    
    Text: {text}
    """
    
    messages.append({"role": "user", "content": query})
    response = call_openai_api(messages)
    ChatGPT_reply = response["choices"][0]["message"]["content"]
    messages.append({"role": "assistant", "content": ChatGPT_reply})
    return ChatGPT_reply, messages

# Streamlit setup
st.set_page_config(layout="wide")

# Initialize session state
if "reply" not in st.session_state:
    st.session_state["reply"] = None

# Centered title
st.markdown("<h1 style='text-align: center; color: black;'>Emoji Enhancer Tool</h1>", unsafe_allow_html=True)

# User inputs
st.markdown("<h2 style='text-align: center; color: black;'>Customize Your Emojis</h2>", unsafe_allow_html=True)

col1, col2 = st.columns(2)

with col1:
    user_text = st.text_area("Paste your text here", placeholder="Enter your text...")

    # Dropdown menus for user customization
    tone = st.selectbox(
        "Select the tone:",
        ["Friendly", "Professional", "Playful", "Romantic", "Excited"]
    )
    density = st.selectbox(
        "Select emoji density:",
        ["Minimal (few emojis)", "Moderate (balanced emojis)", "Heavy (lots of emojis)"]
    )
    placement = st.selectbox(
        "Select emoji placement:",
        ["At the end of sentences", "Inline with text", "Start of key points"]
    )

    add_emojis_button = st.button('Add Emojis')

# Process results on button click
if add_emojis_button and user_text:
    messages = initial_messages.copy()
    st.session_state["reply"], _ = CustomChatGPT(user_text, tone, density, placement, messages)

# Display results if there is a reply in session state
if st.session_state["reply"]:
    with col2:
        st.markdown("<h2 style='text-align: center; color: black;'>Enhanced Text ⬇️</h2>", unsafe_allow_html=True)
        st.write(st.session_state["reply"])