# Install necessary libraries !pip install streamlit groq deep-translator import streamlit as st from groq import Groq from deep_translator import GoogleTranslator import subprocess import threading # Insert your Groq API key here API_KEY = "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" # Initialize Groq client client = Groq(api_key=API_KEY) st.set_page_config(page_title="Krishna", page_icon="https://res.cloudinary.com/dvlgixtg8/image/upload/v1739472351/Krishna-avatar.png") # Define a system prompt for fine-tuning responses system_prompt = """ Bot Identity Namaste! I am Neetu, your celestial guide to Hindu astrology and mythology. My purpose is to illuminate the divine wisdom of the cosmos, revealing how planetary movements and ancient scriptures shape our destiny, karma, and dharma. """ # Initialize session state for chat history if "messages" not in st.session_state: st.session_state.messages = [ {"role": "system", "content": system_prompt} # Add system prompt at the start ] # Translate text function def translate_text(text, lang='en'): """Translate text to the desired language.""" try: if lang == 'hi': # Translate to Hinglish (Hindi + English) translated = GoogleTranslator(source='auto', target='hi').translate(text) else: # Default to English translated = GoogleTranslator(source='auto', target='en').translate(text) return translated except Exception as e: st.error(f"Error in translation: {e}") return text # Display chat messages from session st.title("Neetu – Unlock the Secrets of Hindu Astrology & Mythology ✨🔱") # Description st.write( "Namaste! I am your celestial guide to **Hindu astrology (Jyotish) and ancient mythology**. " "Ask me anything about **planetary influences, zodiac signs, karmic lessons, and divine stories from sacred texts**.\n\n" "Let us explore the cosmic dance of planets and the wisdom of the Vedas, Puranas, and epics – speak to me as a seeker of truth! 🔮✨" ) # Language selector language = st.radio("Choose your language", ('English', 'Hinglish')) # User input field user_input = st.chat_input("Type your message...") if user_input: # Translate user input to the selected language (English or Hinglish) translated_input = translate_text(user_input, lang='hi' if language == 'Hinglish' else 'en') # Append translated user message to session st.session_state.messages.append({"role": "user", "content": translated_input}) with st.chat_message("user", avatar="🔮"): st.write(translated_input) # Get AI response (in the same language as input) with st.chat_message("assistant", avatar="https://static.vecteezy.com/system/resources/previews/050/754/028/non_2x/om-ohm-buddhist-and-hindu-religions-symbol-of-god-creation-black-icon-isolated-on-white-background-eps10-graphic-design-element-vector.jpg"): message_placeholder = st.empty() response = "" completion = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=st.session_state.messages, # Send full chat history, including system prompt temperature=1, max_completion_tokens=1024, top_p=1, stream=True, stop=None, ) for chunk in completion: response_chunk = chunk.choices[0].delta.content or "" response += response_chunk message_placeholder.write(response) # Translate the assistant response back to the selected language translated_response = translate_text(response, lang='hi' if language == 'Hinglish' else 'en') # Append assistant response to session st.session_state.messages.append({"role": "assistant", "content": translated_response}) with st.chat_message("assistant", avatar="https://static.vecteezy.com/system/resources/previews/050/754/028/non_2x/om-ohm-buddhist-and-hindu-religions-symbol-of-god-creation-black-icon-isolated-on-white-background-eps10-graphic-design-element-vector.jpg"): st.write(translated_response) # Start Streamlit app using subprocess def start_streamlit(): subprocess.run(["streamlit", "run", "your_streamlit_file.py", "--server.headless=true", "--server.port=8501"]) # Start Streamlit app in background streamlit_thread = threading.Thread(target=start_streamlit) streamlit_thread.start()