Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,14 +11,21 @@ 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 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
|
@@ -65,11 +72,16 @@ if prompt := st.chat_input("Say something, I dare you! π"):
|
|
| 65 |
message_placeholder = st.empty()
|
| 66 |
message_placeholder.text("π€")
|
| 67 |
emoji = predict_emoji(prompt)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# Fun facts in an expander
|
| 75 |
with st.expander("π― Did You Know?", expanded=False):
|
|
@@ -80,7 +92,7 @@ with st.expander("π― Did You Know?", expanded=False):
|
|
| 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
|
| 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.",
|
|
|
|
| 11 |
model = "mistral-large-2407" # Using small model for faster responses
|
| 12 |
|
| 13 |
def mistral_api_call(messages):
|
| 14 |
+
try:
|
| 15 |
+
chat_response = client.chat.complete(
|
| 16 |
+
model=model,
|
| 17 |
+
messages=messages,
|
| 18 |
+
temperature=0.9, # Higher temperature for more creative responses
|
| 19 |
+
max_tokens=150, # Increased slightly for more complete responses
|
| 20 |
+
top_p=0.95 # Slightly higher top_p for more varied vocabulary
|
| 21 |
+
)
|
| 22 |
+
return chat_response.choices[0].message.content
|
| 23 |
+
except Exception as e:
|
| 24 |
+
error_message = str(e)
|
| 25 |
+
if "429" in error_message:
|
| 26 |
+
return "π
Oops! I'm a bit overwhelmed right now. Could you try again in a moment? I promise I'll be ready with a witty response!"
|
| 27 |
+
else:
|
| 28 |
+
return f"π Something went wrong on my end. Error: {error_message}"
|
| 29 |
|
| 30 |
SYSTEM_PROMPT = """You are Emojinator, a witty and sarcastic chatbot with a great sense of humor.
|
| 31 |
Your responses should be clever, playful, and sometimes use puns.
|
|
|
|
| 72 |
message_placeholder = st.empty()
|
| 73 |
message_placeholder.text("π€")
|
| 74 |
emoji = predict_emoji(prompt)
|
| 75 |
+
if "π
Oops!" in emoji or "π Something went wrong" in emoji:
|
| 76 |
+
message_placeholder.markdown(emoji)
|
| 77 |
+
st.session_state.messages.append({"role": "assistant", "content": emoji})
|
| 78 |
+
else:
|
| 79 |
+
message_placeholder.text("βοΈ")
|
| 80 |
+
response = generate_response(prompt, emoji)
|
| 81 |
+
full_response = f"{response} {emoji}"
|
| 82 |
+
message_placeholder.markdown(full_response)
|
| 83 |
+
# Add assistant response to history
|
| 84 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 85 |
|
| 86 |
# Fun facts in an expander
|
| 87 |
with st.expander("π― Did You Know?", expanded=False):
|
|
|
|
| 92 |
"There are over 3,000 emojis in the Unicode Standard as of 2021.",
|
| 93 |
"The word 'emoji' comes from Japanese e (η΅΅, 'picture') + moji (ζε, 'character').",
|
| 94 |
"Finland is the only country to have its own set of national emojis, including a sauna emoji π§!",
|
| 95 |
+
"Emojis were first introduced on mobile phones by NTT Docomo, Japan's leading mobile operator.",
|
| 96 |
"The most-used emoji on Twitter is the 'Face with Tears of Joy' π, followed by the 'Red Heart' β€οΈ.",
|
| 97 |
"In 2016, the Museum of Modern Art (MoMA) in New York added the original 176 emoji set into its permanent collection.",
|
| 98 |
"World Emoji Day is celebrated every year on July 17, the date shown on the π
Calendar Emoji.",
|