Spaces:
Running
Running
Update pages/deep_learning.py
Browse files- pages/deep_learning.py +8 -18
pages/deep_learning.py
CHANGED
@@ -1,26 +1,22 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
4 |
-
from langchain_core.messages import HumanMessage,
|
5 |
|
6 |
-
# Load Hugging Face token
|
7 |
hf = os.getenv('Data_science')
|
8 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
|
9 |
os.environ['HF_TOKEN'] = hf
|
10 |
|
11 |
-
|
12 |
-
st.
|
13 |
-
st.title("🤖 AI Mentor Chat")
|
14 |
|
15 |
-
# --- Sidebar: Experience Level ---
|
16 |
st.sidebar.title("Mentor Preferences")
|
17 |
experience_label = st.sidebar.selectbox(
|
18 |
"Select your experience level:", ["Beginner", "Intermediate", "Experienced"]
|
19 |
)
|
20 |
|
21 |
-
# --- Initialize Chat Model ---
|
22 |
deep_seek_skeleton = HuggingFaceEndpoint(
|
23 |
-
repo_id='
|
24 |
provider='sambanova',
|
25 |
temperature=0.7,
|
26 |
max_new_tokens=150,
|
@@ -29,38 +25,32 @@ deep_seek_skeleton = HuggingFaceEndpoint(
|
|
29 |
|
30 |
deep_seek = ChatHuggingFace(
|
31 |
llm=deep_seek_skeleton,
|
32 |
-
repo_id='
|
33 |
provider='sambanova',
|
34 |
temperature=0.7,
|
35 |
max_new_tokens=150,
|
36 |
task='conversational'
|
37 |
)
|
38 |
|
39 |
-
PAGE_KEY = "
|
40 |
|
41 |
-
# --- Session State ---
|
42 |
if PAGE_KEY not in st.session_state:
|
43 |
st.session_state[PAGE_KEY] = []
|
44 |
|
45 |
-
# --- Chat Input Form ---
|
46 |
with st.form(key="chat_form"):
|
47 |
user_input = st.text_input("Ask your question:")
|
48 |
submit = st.form_submit_button("Send")
|
49 |
|
50 |
-
# --- Chat Handling ---
|
51 |
if submit and user_input:
|
52 |
-
# System context based on selected experience level
|
53 |
system_prompt = (
|
54 |
-
f"Act as a
|
55 |
f"Teach in a friendly manner and keep answers within 150 words. "
|
56 |
-
f"If a question is
|
57 |
)
|
58 |
-
|
59 |
messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
|
60 |
result = deep_seek.invoke(messages)
|
61 |
st.session_state[PAGE_KEY].append((user_input, result.content))
|
62 |
|
63 |
-
# --- Chat History Display ---
|
64 |
st.subheader("🗨️ Chat History")
|
65 |
for user, bot in st.session_state[PAGE_KEY]:
|
66 |
st.markdown(f"**You:** {user}")
|
|
|
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 |
hf = os.getenv('Data_science')
|
7 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
|
8 |
os.environ['HF_TOKEN'] = hf
|
9 |
|
10 |
+
st.set_page_config(page_title="Python Mentor Chat", layout="centered")
|
11 |
+
st.title("🐍 Python Mentor Chat")
|
|
|
12 |
|
|
|
13 |
st.sidebar.title("Mentor Preferences")
|
14 |
experience_label = st.sidebar.selectbox(
|
15 |
"Select your experience level:", ["Beginner", "Intermediate", "Experienced"]
|
16 |
)
|
17 |
|
|
|
18 |
deep_seek_skeleton = HuggingFaceEndpoint(
|
19 |
+
repo_id='meta-llama/Llama-3.2-3B-Instruct',
|
20 |
provider='sambanova',
|
21 |
temperature=0.7,
|
22 |
max_new_tokens=150,
|
|
|
25 |
|
26 |
deep_seek = ChatHuggingFace(
|
27 |
llm=deep_seek_skeleton,
|
28 |
+
repo_id='meta-llama/Llama-3.2-3B-Instruct',
|
29 |
provider='sambanova',
|
30 |
temperature=0.7,
|
31 |
max_new_tokens=150,
|
32 |
task='conversational'
|
33 |
)
|
34 |
|
35 |
+
PAGE_KEY = "python_chat_history"
|
36 |
|
|
|
37 |
if PAGE_KEY not in st.session_state:
|
38 |
st.session_state[PAGE_KEY] = []
|
39 |
|
|
|
40 |
with st.form(key="chat_form"):
|
41 |
user_input = st.text_input("Ask your question:")
|
42 |
submit = st.form_submit_button("Send")
|
43 |
|
|
|
44 |
if submit and user_input:
|
|
|
45 |
system_prompt = (
|
46 |
+
f"Act as a python mentor with {experience_label.lower()} experience. "
|
47 |
f"Teach in a friendly manner and keep answers within 150 words. "
|
48 |
+
f"If a question is not about python, politely mention it's out of scope."
|
49 |
)
|
|
|
50 |
messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
|
51 |
result = deep_seek.invoke(messages)
|
52 |
st.session_state[PAGE_KEY].append((user_input, result.content))
|
53 |
|
|
|
54 |
st.subheader("🗨️ Chat History")
|
55 |
for user, bot in st.session_state[PAGE_KEY]:
|
56 |
st.markdown(f"**You:** {user}")
|