File size: 1,194 Bytes
fd07e90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 streamlit as st

# Define a dictionary mapping words to emojis
emoji_mapping = {
    "happy": "😊",
    "sad": "😒",
    "love": "❀️",
    "angry": "😑",
    "sun": "β˜€οΈ",
    "star": "⭐",
    "fire": "πŸ”₯",
    "cool": "😎",
    "cat": "🐱",
    "dog": "🐢",
}

# Function to convert text to emojis
def text_to_emoji(text):
    words = text.split()
    converted_text = []
    for word in words:
        # Replace word with emoji if it exists in the mapping
        converted_text.append(emoji_mapping.get(word.lower(), word))
    return " ".join(converted_text)

# Streamlit UI
st.title("Text to Emoji Converter")
st.write("Convert your sentences into emojis! Type some text below and see the magic. πŸ˜ƒ")

# User input
user_input = st.text_input("Enter your text here:", placeholder="e.g., I am happy and love the sun!")

# Convert and display the result
if user_input:
    output = text_to_emoji(user_input)
    st.write("### Converted Text:")
    st.write(output)
    st.write("✨ Enjoy your emojis!")

st.write("---")
st.write("Built with ❀️ using [Streamlit](https://streamlit.io/) and hosted on [Hugging Face Spaces](https://huggingface.co/spaces).")