67Ayush87 commited on
Commit
1a317f9
·
verified ·
1 Parent(s): 1ae40b2

Update pages/deep_learning.py

Browse files
Files changed (1) hide show
  1. pages/deep_learning.py +106 -2
pages/deep_learning.py CHANGED
@@ -54,7 +54,111 @@ st.title("🐍 Python Mentor Chat")
54
 
55
  # Sidebar
56
  st.sidebar.title("Mentor Preferences")
57
- experience_label = st.sidebar.selectbox(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  "Select your experience level:", ["Beginner", "Intermediate", "Experienced"]
59
  )
60
 
@@ -63,7 +167,7 @@ deep_seek_skeleton = HuggingFaceEndpoint(
63
  repo_id='meta-llama/Llama-3.2-3B-Instruct',
64
  provider='sambanova',
65
  temperature=0.7,
66
- max_new_tokens=150,
67
  task='conversational'
68
  )
69
  deep_seek = ChatHuggingFace(
 
54
 
55
  # Sidebar
56
  st.sidebar.title("Mentor Preferences")
57
+ experience_label = st.sidebar.selectbox(import streamlit as st
58
+ import os
59
+ from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
60
+ from langchain_core.messages import HumanMessage, SystemMessage
61
+
62
+ # Set environment variables for Hugging Face token
63
+ hf = os.getenv('hf')
64
+ os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
65
+ os.environ['HF_TOKEN'] = hf
66
+
67
+ # Page config
68
+ st.set_page_config(page_title="Deep Learning Mentor Chat", layout="centered")
69
+
70
+ # Inject CSS styling from homepage
71
+ st.markdown("""
72
+ <style>
73
+ .main {
74
+ background: linear-gradient(135deg, #430089 0%, #82ffa1 100%);
75
+ padding: 2rem;
76
+ font-family: 'Segoe UI', sans-serif;
77
+ }
78
+ .stButton>button {
79
+ background: #ffffff10;
80
+ border: 2px solid #ffffff50;
81
+ color: white;
82
+ font-size: 18px;
83
+ font-weight: 600;
84
+ padding: 0.8em 1.2em;
85
+ border-radius: 12px;
86
+ width: 100%;
87
+ transition: 0.3s ease;
88
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
89
+ }
90
+ .stButton>button:hover {
91
+ background: #ffffff30;
92
+ border-color: #fff;
93
+ color: #ffffff;
94
+ }
95
+ h1, h3, p, label {
96
+ color: #ffffff;
97
+ text-align: center;
98
+ }
99
+ hr {
100
+ border: 1px solid #ffffff50;
101
+ margin: 2em 0;
102
+ }
103
+ .css-1aumxhk {
104
+ color: white;
105
+ }
106
+ </style>
107
+ """, unsafe_allow_html=True)
108
+
109
+ # Title
110
+ st.title("🧠 Deep Learning Mentor Chat")
111
+
112
+ # Sidebar experience selector
113
+ st.sidebar.title("Mentor Preferences")
114
+ exp = st.sidebar.selectbox("Select experience level:", ['Beginner', 'Intermediate', 'Expert'])
115
+
116
+ # Initialize LLM
117
+ mentor_llm = HuggingFaceEndpoint(
118
+ repo_id='Qwen/Qwen3-32B',
119
+ provider='sambanova',
120
+ temperature=0.7,
121
+ max_new_tokens=150,
122
+ task='conversational'
123
+ )
124
+
125
+ deep_mentor = ChatHuggingFace(
126
+ llm=mentor_llm,
127
+ repo_id='Qwen/Qwen3-32B',
128
+ provider='sambanova',
129
+ temperature=0.7,
130
+ max_new_tokens=150,
131
+ task='conversational'
132
+ )
133
+
134
+ # Session key
135
+ PAGE_KEY = "deep_learning_chat_history"
136
+ if PAGE_KEY not in st.session_state:
137
+ st.session_state[PAGE_KEY] = []
138
+
139
+ # Chat form
140
+ with st.form(key="chat_form"):
141
+ user_input = st.text_input("Ask your question:")
142
+ submit = st.form_submit_button("Send")
143
+
144
+ # Handle submission
145
+ if submit and user_input:
146
+ system_prompt = (
147
+ f"You are a deep learning mentor with {exp.lower()} level expertise. "
148
+ f"Answer only deep learning-related questions, teach in a friendly tone, and limit responses to 150 words. "
149
+ f"If a question is outside deep learning, politely say it's out of scope."
150
+ )
151
+ messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
152
+ result = deep_mentor.invoke(messages)
153
+ st.session_state[PAGE_KEY].append((user_input, result.content))
154
+
155
+ # Display chat history
156
+ st.subheader("🗨️ Chat History")
157
+ for user, bot in st.session_state[PAGE_KEY]:
158
+ st.markdown(f"**You:** {user}")
159
+ st.markdown(f"**Mentor:** {bot}")
160
+ st.markdown("---")
161
+
162
  "Select your experience level:", ["Beginner", "Intermediate", "Experienced"]
163
  )
164
 
 
167
  repo_id='meta-llama/Llama-3.2-3B-Instruct',
168
  provider='sambanova',
169
  temperature=0.7,
170
+ max_new_tokens=50,
171
  task='conversational'
172
  )
173
  deep_seek = ChatHuggingFace(