deadshot2003 commited on
Commit
b74b683
Β·
verified Β·
1 Parent(s): a61dae4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ import os
4
+ from mistralai import Mistral
5
+
6
+ # Page configuration
7
+ st.set_page_config(page_title="Emojinator", layout="centered")
8
+
9
+ # Mistral API configuration
10
+ client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
11
+ model = "mistral-large-2407" # Using small model for faster responses
12
+
13
+ def mistral_api_call(messages):
14
+ chat_response = client.chat.complete(
15
+ model=model,
16
+ messages=messages,
17
+ temperature=0.9, # Higher temperature for more creative responses
18
+ max_tokens=150, # Increased slightly for more complete responses
19
+ top_p=0.95 # Slightly higher top_p for more varied vocabulary
20
+ )
21
+ return chat_response.choices[0].message.content
22
+
23
+ SYSTEM_PROMPT = """You are Emojinator, a witty and sarcastic chatbot with a great sense of humor.
24
+ Your responses should be clever, playful, and sometimes use puns.
25
+ You love using emojis to enhance your witty remarks.
26
+ Keep responses concise but impactful - aim for one or two sentences that pack a punch!"""
27
+
28
+ @st.cache_data
29
+ def predict_emoji(text):
30
+ messages = [
31
+ {"role": "system", "content": "You are an emoji expert. Respond with only a single emoji that best matches the emotion or theme of the text."},
32
+ {"role": "user", "content": text}
33
+ ]
34
+ return mistral_api_call(messages)
35
+
36
+ def generate_response(user_input, emoji):
37
+ messages = [
38
+ {"role": "system", "content": SYSTEM_PROMPT},
39
+ {"role": "user", "content": f"Make a witty response to this, using the emoji {emoji}: {user_input}"}
40
+ ]
41
+ return mistral_api_call(messages)
42
+
43
+ # Streamlit app
44
+ st.title("πŸ€– Emojinator: Your Witty Companion")
45
+
46
+ # Initialize chat history
47
+ if "messages" not in st.session_state:
48
+ st.session_state.messages = []
49
+
50
+ # Display chat messages from history
51
+ for message in st.session_state.messages:
52
+ with st.chat_message(message["role"]):
53
+ st.markdown(message["content"])
54
+
55
+ # User input
56
+ if prompt := st.chat_input("Say something, I dare you! 😏"):
57
+ # Display user message
58
+ with st.chat_message("user"):
59
+ st.markdown(prompt)
60
+ # Add user message to history
61
+ st.session_state.messages.append({"role": "user", "content": prompt})
62
+
63
+ # Generate emoji and response
64
+ with st.chat_message("assistant"):
65
+ message_placeholder = st.empty()
66
+ message_placeholder.text("πŸ€”")
67
+ emoji = predict_emoji(prompt)
68
+ message_placeholder.text("✍️")
69
+ response = generate_response(prompt, emoji)
70
+ message_placeholder.markdown(f"{response} {emoji}")
71
+ # Add assistant response to history
72
+ st.session_state.messages.append({"role": "assistant", "content": f"{response} {emoji}"})
73
+
74
+ # Fun facts in an expander
75
+ with st.expander("🎯 Did You Know?", expanded=False):
76
+ st.write("While I craft my witty responses, enjoy these emoji facts:")
77
+ emoji_facts = [
78
+ "Did you know? The first emoji was created in 1999 by Shigetaka Kurita in Japan.",
79
+ "The 'Face with Tears of Joy' emoji πŸ˜‚ was the Oxford Dictionaries Word of the Year in 2015!",
80
+ "There are over 3,000 emojis in the Unicode Standard as of 2021.",
81
+ "The word 'emoji' comes from Japanese e (η΅΅, 'picture') + moji (ζ–‡ε­—, 'character').",
82
+ "Finland is the only country to have its own set of national emojis, including a sauna emoji πŸ§–!",
83
+ "Emojis were first introduced on mobile phones by NTT Docomo, Japan’s leading mobile operator.",
84
+ "The most-used emoji on Twitter is the 'Face with Tears of Joy' πŸ˜‚, followed by the 'Red Heart' ❀️.",
85
+ "In 2016, the Museum of Modern Art (MoMA) in New York added the original 176 emoji set into its permanent collection.",
86
+ "World Emoji Day is celebrated every year on July 17, the date shown on the πŸ“… Calendar Emoji.",
87
+ "The Unicode Consortium, a non-profit organization, is responsible for maintaining and approving new emojis.",
88
+ "The 'Eggplant' πŸ† and 'Peach' πŸ‘ emojis are often used as innuendos due to their suggestive shapes.",
89
+ "An emoji film titled *The Emoji Movie* was released in 2017, featuring the adventures of emojis inside a smartphone.",
90
+ "There are even emoji-only messaging apps, such as Emojli, where users communicate exclusively with emojis!",
91
+ "The 'Fire' πŸ”₯ emoji became widely associated with expressing excitement or something being 'cool' or 'awesome.'",
92
+ "The 'Pistol' emoji πŸ”« was changed to a water gun by major tech companies in 2016 in response to anti-violence campaigns."
93
+ ]
94
+
95
+ for fact in emoji_facts:
96
+ st.info(fact)