deadshot2003 commited on
Commit
2456deb
Β·
verified Β·
1 Parent(s): 406a3cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
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
- 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.
@@ -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
- 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):
@@ -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’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.",
 
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.",