File size: 3,353 Bytes
15a2774
470de69
15a2774
a5d14c5
 
4ea3c16
db5150f
a5d14c5
470de69
 
b45e827
db5150f
a5d14c5
a108fb3
a5d14c5
 
 
 
b45e827
 
a5d14c5
 
acae1ee
a5d14c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b45e827
a5d14c5
 
b45e827
a5d14c5
 
 
 
 
 
 
b45e827
a5d14c5
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import streamlit as st
import os
from langchain_community.chat_models import ChatHuggingFace
from langchain_community.llms import HuggingFaceEndpoint
from langchain_core.messages import HumanMessage, SystemMessage, AIMessage


hf_token = os.getenv("Data_science")  
os.environ["HUGGINGFACEHUB_API_KEY"] = hf_token
os.environ["HF_TOKEN"] = hf_token


model = HuggingFaceEndpoint(
    repo_id="Qwen/Qwen3-32B",
    provider="nebius",
    temperature=0.6,
    max_new_tokens=300,
    task="conversational"
)

chat_model = ChatHuggingFace(
    llm=model,
    repo_id="Qwen/Qwen3-32B",
    provider="nebius",
    temperature=0.6,
    max_new_tokens=300,
    task="conversational"
)

# --- Streamlit styles ---
st.markdown("""
<style>
    .subject-btn {
        display: inline-block;
        margin: 0.3em;
    }
    .output-box {
        background-color: #f9f9f9;
        border-radius: 10px;
        padding: 20px;
        margin-top: 20px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    }
</style>
""", unsafe_allow_html=True)

# --- Session state ---
if "message_history" not in st.session_state:
    st.session_state.message_history = []

if "selected_subject" not in st.session_state:
    st.session_state.selected_subject = "Python"

# --- UI Header ---
st.title("πŸŽ“ Data Science Mentor")
st.markdown("Ask subject-specific questions and get guidance based on your experience level.")

# --- Experience level ---
experience = st.selectbox("πŸ‘€ Select your experience level:", ["Beginner", "Intermediate", "Expert"])

# --- Subject buttons ---
st.markdown("### πŸ“š Choose a Subject:")
cols = st.columns(4)
subjects = ["Python", "SQL", "Power BI", "Statistics", "Machine Learning", "Deep Learning", "Generative AI"]
for i, subject in enumerate(subjects):
    if cols[i % 4].button(subject):
        st.session_state.selected_subject = subject
        st.session_state.message_history = []  # Reset chat on subject change

# --- System Message ---
system_prompt = f"""
You are a highly knowledgeable data science mentor specialized in {st.session_state.selected_subject}.
Your job is to guide a {experience.lower()} learner with clear, concise, and actionable advice.
Explain concepts, best practices, and answer questions with patience and professionalism.
If relevant, include example code, use-cases, or tips.
"""
if not st.session_state.message_history:
    st.session_state.message_history.append(SystemMessage(content=system_prompt))

# --- Chat Input ---
user_question = st.text_input(f"πŸ’¬ Ask your {st.session_state.selected_subject} question:")

if st.button("Ask Mentor"):
    if user_question.strip():
        with st.spinner("Thinking..."):
            st.session_state.message_history.append(HumanMessage(content=user_question))
            try:
                response = chat_model.invoke(st.session_state.message_history)
                st.session_state.message_history.append(AIMessage(content=response.content))

                st.markdown('<div class="output-box">', unsafe_allow_html=True)
                st.markdown("### 🧠 Mentor's Response:")
                st.markdown(response.content)
                st.markdown("</div>", unsafe_allow_html=True)
            except Exception as e:
                st.error(f"❌ Error: {e}")
    else:
        st.warning("⚠️ Please enter a question before submitting.")