\"The only way to do great work is to love what you do.\"
", unsafe_allow_html=True) st.title("DilBot: Your Emotional Companion") st.markdown("---") # === Input Section === # Label color is now white via CSS user_input = st.text_area("How are you feeling today?", height=150, placeholder="Type your thoughts here...") if st.button("Analyze"): if user_input.strip(): # Detect Emotion emotion, polarity = detect_emotion(user_input) confidence = abs(polarity) * 100 # Display Emotion - now white text on transparent black background st.subheader("Detected Emotion:") st.success(f"**{emotion.capitalize()}** with a confidence of **{confidence:.2f}%**") # Show a personal quote - now white text on transparent black background st.markdown("### DilBot's Message:") quote = get_quote(emotion)[0] st.info(f"_{quote}_") # === Personal Dashboard === st.markdown("### Personal Dashboard") # Bar & Doughnut Chart fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), dpi=100) labels = ['Positive', 'Neutral', 'Negative'] display_values = [0, 0, 0] if emotion == 'positive': display_values[0] = confidence remaining = 100 - confidence display_values[1] = remaining / 2 display_values[2] = remaining / 2 elif emotion == 'negative': display_values[2] = confidence remaining = 100 - confidence display_values[0] = remaining / 2 display_values[1] = remaining / 2 else: # neutral display_values[1] = confidence remaining = 100 - confidence display_values[0] = remaining / 2 display_values[2] = remaining / 2 # Ensure values sum to 100 for the pie chart total_sum = sum(display_values) if total_sum != 0: display_values = [v * 100 / total_sum for v in display_values] colors = ['#00cc99', '#b0bec5', '#ff6f61'] # Set chart backgrounds to white ax1.set_facecolor('white') ax2.set_facecolor('white') fig.patch.set_facecolor('white') # Entire figure background white # Bar Chart ax1.bar(labels, display_values, color=colors) ax1.set_title("Confidence by Emotion", color='black') ax1.set_ylabel("Percentage", color='black') ax1.tick_params(axis='x', colors='black') ax1.tick_params(axis='y', colors='black') ax1.spines['bottom'].set_color('black') ax1.spines['left'].set_color('black') ax1.spines['top'].set_visible(False) ax1.spines['right'].set_visible(False) # Doughnut Chart if sum(display_values) > 0: wedges, texts, autotexts = ax2.pie( display_values, labels=labels, autopct='%1.1f%%', colors=colors, startangle=90, wedgeprops=dict(width=0.4) ) ax2.set_title("Emotion Distribution", color='black') for text_obj in texts: text_obj.set_color('black') for autotext_obj in autotexts: autotext_obj.set_color('black') else: ax2.text(0.5, 0.5, 'No data', horizontalalignment='center', verticalalignment='center', transform=ax2.transAxes, color='black') # Use st.columns to center the plot col_left, col_center, col_right = st.columns([0.5, 6, 0.5]) with col_center: st.pyplot(fig) plt.close(fig) else: st.warning("Please write something to analyze.") st.markdown('