import streamlit as st import random import re # Page config st.set_page_config( page_title="Nepali Chatbot", page_icon="ЁЯЗ│ЁЯЗ╡" ) # Simple responses nepali_greetings = ["рдирдорд╕реНрддреЗ! рдХрд╕реНрддреЛ рдЫ?", "рдирдорд╕реНрдХрд╛рд░! рд░рд╛рдореНрд░реЛ рдЫреБред", "рд╣рд╛рд▓ рдХрд╕реНрддреЛ рдЫ?"] english_greetings = ["Hello! How are you?", "Hi there!", "Hey! How's it going?"] nepali_responses = [ "рддреНрдпреЛ рд░рд╛рдореНрд░реЛ рдЫ!", "рдмреБрдЭреЗрдВред рдЕрд░реВ рдХреЗ рднрдиреНрди рдЪрд╛рд╣рдиреБрд╣реБрдиреНрдЫ?", "рдзрдиреНрдпрд╡рд╛рдж рд╕рд╛рдЭрд╛ рдЧрд░реНрдиреБрднрдПрдХреЛрдорд╛!", "рддреНрдпреЛ рджрд┐рд▓рдЪрд╕реНрдк рдЫ!" ] english_responses = [ "That's great!", "I understand. What else would you like to say?", "Thanks for sharing!", "That's interesting!" ] def is_nepali(text): return bool(re.search(r'[\u0900-\u097F]', text)) def get_response(message): if not message: return "Please say something!" message_lower = message.lower() # Check for greetings if any(word in message_lower for word in ["hello", "hi", "hey"]) or "рдирдорд╕реНрддреЗ" in message or "рдирдорд╕реНрдХрд╛рд░" in message: return random.choice(nepali_greetings if is_nepali(message) else english_greetings) # Regular responses if is_nepali(message): return random.choice(nepali_responses) else: return random.choice(english_responses) # Title st.title("ЁЯЗ│ЁЯЗ╡ Simple Nepali Chatbot") st.write("**Chat in Nepali or English! / рдиреЗрдкрд╛рд▓реА рд╡рд╛ рдЕрдВрдЧреНрд░реЗрдЬреАрдорд╛ рдХреБрд░рд╛ рдЧрд░реНрдиреБрд╣реЛрд╕реН!**") # Initialize chat history if "messages" not in st.session_state: st.session_state.messages = [] # Display chat messages for message in st.session_state.messages: with st.chat_message(message["role"]): st.write(message["content"]) # Chat input if prompt := st.chat_input("Type here... / рдпрд╣рд╛рдБ рд▓реЗрдЦреНрдиреБрд╣реЛрд╕реН..."): # Add user message st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user"): st.write(prompt) # Generate response response = get_response(prompt) st.session_state.messages.append({"role": "assistant", "content": response}) with st.chat_message("assistant"): st.write(response) # Sidebar with examples with st.sidebar: st.header("Examples / рдЙрджрд╛рд╣рд░рдг") if st.button("рдирдорд╕реНрддреЗ!"): st.session_state.messages.append({"role": "user", "content": "рдирдорд╕реНрддреЗ!"}) st.session_state.messages.append({"role": "assistant", "content": get_response("рдирдорд╕реНрддреЗ!")}) st.rerun() if st.button("Hello!"): st.session_state.messages.append({"role": "user", "content": "Hello!"}) st.session_state.messages.append({"role": "assistant", "content": get_response("Hello!")}) st.rerun() if st.button("Clear / рд╕рдлрд╛ рдЧрд░реНрдиреБрд╣реЛрд╕реН"): st.session_state.messages = [] st.rerun()