67Ayush87 commited on
Commit
1b92457
Β·
verified Β·
1 Parent(s): 964f1df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -83
app.py CHANGED
@@ -1,95 +1,64 @@
1
  import streamlit as st
2
- import os
3
- from langchain_community.chat_models import ChatHuggingFace
4
- from langchain_community.llms import HuggingFaceEndpoint
5
- from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
6
 
7
- # --- Load API Token ---
8
- hf_token = os.getenv("Data_science")
9
- if not hf_token:
10
- st.error("❌ Hugging Face token not found. Please set the 'Data_science' environment variable.")
11
- st.stop()
12
 
13
- os.environ["HUGGINGFACEHUB_API_KEY"] = hf_token
14
- os.environ["HF_TOKEN"] = hf_token
15
-
16
- # --- Load Hugging Face model (Qwen) ---
17
- model = HuggingFaceEndpoint(
18
- repo_id="Qwen/Qwen3-32B",
19
- provider="nebius",
20
- temperature=0.6,
21
- max_new_tokens=500,
22
- task="text-generation"
23
- )
24
-
25
- chat_model = ChatHuggingFace(llm=model)
26
-
27
- # --- Streamlit styles ---
28
  st.markdown("""
29
- <style>
30
- .subject-btn {
31
- display: inline-block;
32
- margin: 0.3em;
33
  }
34
- .output-box {
35
- background-color: #f9f9f9;
 
 
36
  border-radius: 10px;
37
- padding: 20px;
38
- margin-top: 20px;
39
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
 
 
 
 
 
 
 
40
  }
41
- </style>
 
 
 
42
  """, unsafe_allow_html=True)
43
 
44
- # --- Session state ---
45
- if "message_history" not in st.session_state:
46
- st.session_state.message_history = []
47
-
48
- if "selected_subject" not in st.session_state:
49
- st.session_state.selected_subject = "Python"
50
-
51
- # --- UI Header ---
52
- st.title("πŸŽ“ Data Science Mentor")
53
- st.markdown("Ask subject-specific questions and get guidance based on your experience level.")
54
-
55
- # --- Experience level ---
56
- experience = st.selectbox("πŸ‘€ Select your experience level:", ["Beginner", "Intermediate", "Expert"])
57
-
58
- # --- Subject buttons ---
59
- st.markdown("### πŸ“š Choose a Subject:")
60
- cols = st.columns(4)
61
- subjects = ["Python", "SQL", "Power BI", "Statistics", "Machine Learning", "Deep Learning", "Generative AI"]
62
- for i, subject in enumerate(subjects):
63
- if cols[i % 4].button(subject):
64
- st.session_state.selected_subject = subject
65
- st.session_state.message_history = [] # Reset chat on subject change
66
-
67
- # --- Set system message based on subject & experience ---
68
- if not st.session_state.message_history:
69
- system_prompt = f"""
70
- You are a highly knowledgeable data science mentor specialized in {st.session_state.selected_subject}.
71
- Your job is to guide a {experience.lower()} learner with clear, concise, and actionable advice.
72
- Explain concepts, best practices, and answer questions with patience and professionalism.
73
- If relevant, include example code, use-cases, or tips.
74
- """
75
- st.session_state.message_history.append(SystemMessage(content=system_prompt.strip()))
76
 
77
- # --- Chat Input ---
78
- user_question = st.text_input(f"πŸ’¬ Ask your {st.session_state.selected_subject} question:")
 
 
 
 
 
 
79
 
80
- if st.button("Ask Mentor"):
81
- if user_question.strip():
82
- with st.spinner("Thinking..."):
83
- st.session_state.message_history.append(HumanMessage(content=user_question))
84
- try:
85
- response = chat_model.invoke(st.session_state.message_history)
86
- st.session_state.message_history.append(AIMessage(content=response.content))
87
 
88
- st.markdown('<div class="output-box">', unsafe_allow_html=True)
89
- st.markdown("### 🧠 Mentor's Response:")
90
- st.markdown(response.content)
91
- st.markdown("</div>", unsafe_allow_html=True)
92
- except Exception as e:
93
- st.error(f"❌ Error: {e}")
94
- else:
95
- st.warning("⚠️ Please enter a question before submitting.")
 
1
  import streamlit as st
 
 
 
 
2
 
3
+ # Set page config
4
+ st.set_page_config(page_title="Innomatics Online Trainer Bot", layout="centered")
 
 
 
5
 
6
+ # Inject custom CSS for background and buttons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  st.markdown("""
8
+ <style>
9
+ .main {
10
+ background-color: #8B0000;
11
+ padding: 20px;
12
  }
13
+ .stButton>button {
14
+ background-color: #B76F27;
15
+ color: #8B0000;
16
+ border: 2px solid #8B0000;
17
  border-radius: 10px;
18
+ padding: 10px 20px;
19
+ font-size: 18px;
20
+ font-weight: bold;
21
+ width: 100%;
22
+ transition: 0.3s ease-in-out;
23
+ }
24
+ .stButton>button:hover {
25
+ background-color: #8B0000;
26
+ color: #ffffff;
27
+ border: 2px solid white;
28
  }
29
+ h1, h3, p {
30
+ color: white;
31
+ }
32
+ </style>
33
  """, unsafe_allow_html=True)
34
 
35
+ # Title and intro
36
+ st.title("Innomatics Online Trainer Bot")
37
+ st.markdown("### πŸ‘‹ Welcome to the Innomatics Online Trainer Bot!")
38
+ st.markdown("This dashboard will guide you through your doubts in various modules.")
39
+ st.markdown("## In which module do you have doubt?")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ # Button layout - 2 per row
42
+ col1, col2 = st.columns(2)
43
+ with col1:
44
+ if st.button("Python"):
45
+ st.switch_page("pages/python.py")
46
+ with col2:
47
+ if st.button("Machine Learning"):
48
+ st.switch_page("pages/machine_learning.py")
49
 
50
+ col3, col4 = st.columns(2)
51
+ with col3:
52
+ if st.button("Deep Learning"):
53
+ st.switch_page("pages/deep_learning.py")
54
+ with col4:
55
+ if st.button("Statistics"):
56
+ st.switch_page("pages/statistics.py")
57
 
58
+ col5, col6 = st.columns(2)
59
+ with col5:
60
+ if st.button("Excel"):
61
+ st.switch_page("pages/excel.py")
62
+ with col6:
63
+ if st.button("SQL"):
64
+ st.switch_page("pages/sql.py")