Akhil4839 commited on
Commit
a1ce214
Β·
verified Β·
1 Parent(s): 2c108cc

Create 3_Deep_learning.py

Browse files
Files changed (1) hide show
  1. pages/3_Deep_learning.py +120 -0
pages/3_Deep_learning.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
4
+ from langchain_core.messages import HumanMessage, SystemMessage
5
+
6
+ # Set environment variables for Hugging Face token
7
+ hf = os.getenv('Data_science')
8
+ os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
9
+ os.environ['HF_TOKEN'] = hf
10
+
11
+ # Page config
12
+ st.set_page_config(page_title="🧠 Deep Learning Mentor Chat", page_icon="πŸ”¬", layout="centered")
13
+
14
+ # Inject Custom CSS Styling
15
+ st.markdown("""
16
+ <style>
17
+ .main {
18
+ background: linear-gradient(135deg, #1d2671 0%, #c33764 100%);
19
+ padding: 2rem;
20
+ font-family: 'Segoe UI', sans-serif;
21
+ }
22
+ h1, h2, h3, h4, h5, h6, p, label, .css-10trblm, .css-q8sbsg {
23
+ color: #ffffff !important;
24
+ text-align: center;
25
+ }
26
+ .stTextInput>div>div>input {
27
+ background-color: rgba(255, 255, 255, 0.1);
28
+ color: white;
29
+ border: 1px solid rgba(255, 255, 255, 0.5);
30
+ border-radius: 8px;
31
+ padding: 0.6em;
32
+ }
33
+ .stTextInput>div>div>input::placeholder {
34
+ color: rgba(255, 255, 255, 0.6);
35
+ }
36
+ .stButton>button {
37
+ background: rgba(255, 255, 255, 0.15);
38
+ border: 2px solid rgba(255, 255, 255, 0.4);
39
+ color: white;
40
+ font-size: 18px;
41
+ font-weight: bold;
42
+ padding: 0.8em 1.2em;
43
+ border-radius: 12px;
44
+ width: 100%;
45
+ transition: all 0.3s ease;
46
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
47
+ }
48
+ .stButton>button:hover {
49
+ background: rgba(255, 255, 255, 0.3);
50
+ border-color: white;
51
+ color: white;
52
+ }
53
+ .stSidebar > div:first-child {
54
+ background: #2c3e50;
55
+ padding: 1rem;
56
+ border-radius: 0 15px 15px 0;
57
+ }
58
+ .stSidebar h1, .stSidebar h2, .stSidebar h3, .stSidebar label, .stSidebar p {
59
+ color: white !important;
60
+ }
61
+ hr {
62
+ border: 1px solid rgba(255, 255, 255, 0.3);
63
+ margin: 2em 0;
64
+ }
65
+ </style>
66
+ """, unsafe_allow_html=True)
67
+
68
+ # --- Title ---
69
+ st.title("🧠 Deep Learning Mentor Chat")
70
+ st.markdown("### πŸ’‘ Ask questions on neural networks, architectures, optimization, and more!")
71
+
72
+ # --- Sidebar: Experience Level ---
73
+ st.sidebar.title("πŸ§‘β€πŸ« Mentor Preferences")
74
+ exp = st.sidebar.selectbox("πŸŽ“ Choose your experience level:", ['Beginner', 'Intermediate', 'Expert'])
75
+
76
+ # --- Load Deep Learning Model ---
77
+ mentor_llm = HuggingFaceEndpoint(
78
+ repo_id='Qwen/Qwen3-32B',
79
+ provider='sambanova',
80
+ temperature=0.7,
81
+ max_new_tokens=150,
82
+ task='conversational'
83
+ )
84
+
85
+ deep_mentor = ChatHuggingFace(
86
+ llm=mentor_llm,
87
+ repo_id='Qwen/Qwen3-32B',
88
+ provider='sambanova',
89
+ temperature=0.7,
90
+ max_new_tokens=150,
91
+ task='conversational'
92
+ )
93
+
94
+ # --- Session State Initialization ---
95
+ PAGE_KEY = "deep_learning_chat_history"
96
+ if PAGE_KEY not in st.session_state:
97
+ st.session_state[PAGE_KEY] = []
98
+
99
+ # --- Chat Input Form ---
100
+ with st.form(key="chat_form"):
101
+ user_input = st.text_input("🧠 Ask your Deep Learning question:", placeholder="e.g. What is the vanishing gradient problem?")
102
+ submit = st.form_submit_button("πŸš€ Send")
103
+
104
+ # --- Handle Submission ---
105
+ if submit and user_input:
106
+ system_prompt = (
107
+ f"You are a deep learning mentor with {exp.lower()} level expertise. "
108
+ f"Answer only deep learning-related questions in a friendly, concise manner. "
109
+ f"Keep answers under 150 words. Politely decline non-DL topics."
110
+ )
111
+ messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
112
+ result = deep_mentor.invoke(messages)
113
+ st.session_state[PAGE_KEY].append((user_input, result.content))
114
+
115
+ # --- Display Chat History ---
116
+ st.subheader("πŸ“œ Chat History")
117
+ for user, bot in st.session_state[PAGE_KEY]:
118
+ st.markdown(f"**πŸ§‘ You:** {user}")
119
+ st.markdown(f"**πŸ€– Mentor:** {bot}")
120
+ st.markdown("---")