Spaces:
Running
Running
Update pages/deep_learning.py
Browse files- pages/deep_learning.py +48 -3
pages/deep_learning.py
CHANGED
@@ -7,14 +7,58 @@ 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',
|
@@ -22,25 +66,25 @@ deep_seek_skeleton = HuggingFaceEndpoint(
|
|
22 |
max_new_tokens=150,
|
23 |
task='conversational'
|
24 |
)
|
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=
|
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. "
|
@@ -51,6 +95,7 @@ if submit and 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}")
|
|
|
7 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
|
8 |
os.environ['HF_TOKEN'] = hf
|
9 |
|
10 |
+
# Page config
|
11 |
st.set_page_config(page_title="Python Mentor Chat", layout="centered")
|
12 |
+
|
13 |
+
# Inject home page CSS style
|
14 |
+
st.markdown("""
|
15 |
+
<style>
|
16 |
+
.main {
|
17 |
+
background: linear-gradient(135deg, #430089 0%, #82ffa1 100%);
|
18 |
+
padding: 2rem;
|
19 |
+
font-family: 'Segoe UI', sans-serif;
|
20 |
+
}
|
21 |
+
.stButton>button {
|
22 |
+
background: #ffffff10;
|
23 |
+
border: 2px solid #ffffff50;
|
24 |
+
color: white;
|
25 |
+
font-size: 18px;
|
26 |
+
font-weight: 600;
|
27 |
+
padding: 0.8em 1.2em;
|
28 |
+
border-radius: 12px;
|
29 |
+
width: 100%;
|
30 |
+
transition: 0.3s ease;
|
31 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
|
32 |
+
}
|
33 |
+
.stButton>button:hover {
|
34 |
+
background: #ffffff30;
|
35 |
+
border-color: #fff;
|
36 |
+
color: #ffffff;
|
37 |
+
}
|
38 |
+
h1, h3, p, label {
|
39 |
+
color: #ffffff;
|
40 |
+
text-align: center;
|
41 |
+
}
|
42 |
+
hr {
|
43 |
+
border: 1px solid #ffffff50;
|
44 |
+
margin: 2em 0;
|
45 |
+
}
|
46 |
+
.css-1aumxhk {
|
47 |
+
color: white;
|
48 |
+
}
|
49 |
+
</style>
|
50 |
+
""", unsafe_allow_html=True)
|
51 |
+
|
52 |
+
# Title
|
53 |
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 |
|
61 |
+
# Initialize model
|
62 |
deep_seek_skeleton = HuggingFaceEndpoint(
|
63 |
repo_id='meta-llama/Llama-3.2-3B-Instruct',
|
64 |
provider='sambanova',
|
|
|
66 |
max_new_tokens=150,
|
67 |
task='conversational'
|
68 |
)
|
|
|
69 |
deep_seek = ChatHuggingFace(
|
70 |
llm=deep_seek_skeleton,
|
71 |
repo_id='meta-llama/Llama-3.2-3B-Instruct',
|
72 |
provider='sambanova',
|
73 |
temperature=0.7,
|
74 |
+
max_new_tokens=50,
|
75 |
task='conversational'
|
76 |
)
|
77 |
|
78 |
PAGE_KEY = "python_chat_history"
|
|
|
79 |
if PAGE_KEY not in st.session_state:
|
80 |
st.session_state[PAGE_KEY] = []
|
81 |
|
82 |
+
# Chat input form
|
83 |
with st.form(key="chat_form"):
|
84 |
user_input = st.text_input("Ask your question:")
|
85 |
submit = st.form_submit_button("Send")
|
86 |
|
87 |
+
# Chat logic
|
88 |
if submit and user_input:
|
89 |
system_prompt = (
|
90 |
f"Act as a python mentor with {experience_label.lower()} experience. "
|
|
|
95 |
result = deep_seek.invoke(messages)
|
96 |
st.session_state[PAGE_KEY].append((user_input, result.content))
|
97 |
|
98 |
+
# Chat history
|
99 |
st.subheader("π¨οΈ Chat History")
|
100 |
for user, bot in st.session_state[PAGE_KEY]:
|
101 |
st.markdown(f"**You:** {user}")
|