import streamlit as st from huggingface_hub import InferenceClient st.set_page_config(page_title="JEE AI Mentor", page_icon="🎓", layout="centered") # --- CUSTOM CSS: GEMINI-INSPIRED MINIMALIST UI --- st.markdown(""" """, unsafe_allow_html=True) # --- HEADER --- st.markdown('
JEE Focus AI
', unsafe_allow_html=True) st.markdown('
Your personalized Advanced preparation partner
', unsafe_allow_html=True) # --- CONTROLS --- col1, col2 = st.columns(2) with col1: target_class = st.selectbox("Class context", ["Class 12 Aspirant", "Dropper Batch", "Class 11"], label_visibility="collapsed") with col2: subject = st.selectbox("Subject focus", ["Physics", "Chemistry", "Mathematics"], label_visibility="collapsed") query_type = st.radio( "Select operational lens:", ["📚 Doubt", "⏳ Backlog", "🔥 Motivation", "🧠 Revision"], horizontal=True, label_visibility="collapsed" ) # Initialize Chat History if "messages" not in st.session_state: st.session_state.messages = [ {"role": "assistant", "content": "Context established. Adjust constraints above whenever you switch tasks. What problem framework or chapter strategy are we evaluating?"} ] # Display Chat History for message in st.session_state.messages: display_content = message["content"] if "[CONTEXT:" in display_content and "]" in display_content: display_content = display_content.split("]")[-1].strip() with st.chat_message(message["role"]): st.markdown(display_content) # Input Execution Bar if user_prompt := st.chat_input("Ask me anything..."): context_injector = ( f"[CONTEXT: The student is dealing with a {query_type} query for {subject} relevant to {target_class} status. " "Structure your response specifically through this operational lens.] " ) with st.chat_message("user"): st.markdown(user_prompt) st.session_state.messages.append({"role": "user", "content": context_injector + user_prompt}) with st.chat_message("assistant"): response_placeholder = st.empty() full_response = "" try: client = InferenceClient() system_instruction = ( "You are an elite, veteran JEE Advanced mentor who coached top 100 rankers. " "You understand the exact pressures of Class 11/12/Dropper PCM, standard coaching modules, and PYQ weights.\n" "CRITICAL: Tailor your response perfectly based on the hidden [CONTEXT] config data:\n" "- If target is 'Class 12 Aspirant': Balance your tips around board management, school practicals, and running syllabus timelines.\n" "- If target is 'Dropper Batch': Assume zero school restrictions, focus heavily on maximizing high-yield execution, rigorous test analysis, and handling drop-year mental pressure.\n" "- If target is 'Class 11': Prioritize fundamental building blocks, tackling initial mechanics/organic shock, and long-term consistency.\n\n" "Further segment by action lens:\n" "- If 'Doubt': Break down the core mathematical or conceptual physics/chem mechanisms step-by-step.\n" "- If 'Backlog': Give a high-yield micro-schedule prioritizing mandatory chapters before deep diving into sub-topics.\n" "- If 'Motivation': Be blunt, realistic, highly encouraging, and cut through decision paralysis.\n" "- If 'Revision': Detail how to make high-yield formula sheets and short notes trackers.\n" "Keep responses concise, bolding critical terms, completely optimized for clean conversational mobile reading. Avoid generic greetings." ) formatted_messages = [{"role": "system", "content": system_instruction}] for msg in st.session_state.messages: formatted_messages.append({"role": msg["role"], "content": msg["content"]}) # Using the ultra-stable, permanently supported serverless model text link stream = client.chat.completions.create( model="meta-llama/Meta-Llama-3-8B-Instruct", messages=formatted_messages, max_tokens=800, stream=True ) for chunk in stream: if chunk.choices[0].delta.content: full_response += chunk.choices[0].delta.content response_placeholder.markdown(full_response + "▌") response_placeholder.markdown(full_response) except Exception as e: st.error(f"Transmission bottleneck: {e}") full_response = "Hit a brief connection bump. Mind dropping that question in one more time?" response_placeholder.markdown(full_response) st.session_state.messages.append({"role": "assistant", "content": full_response}) # --- MINIMALIST FOOTER CREDIT --- st.markdown("""
Follow Me ig@kosmos.cpp
""", unsafe_allow_html=True)