Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,118 +1,103 @@
|
|
1 |
# app.py
|
2 |
-
|
3 |
import streamlit as st
|
4 |
-
from models import
|
5 |
-
|
6 |
-
st.set_page_config(page_title="DeepSeek Chatbot", layout="centered")
|
7 |
-
|
8 |
-
# A helper function to pick the correct Gradio interface
|
9 |
-
def select_demo(model_name):
|
10 |
-
if model_name == "DeepSeek-R1-Distill-Qwen-32B":
|
11 |
-
return demo_qwen
|
12 |
-
elif model_name == "DeepSeek-R1":
|
13 |
-
return demo_r1
|
14 |
-
elif model_name == "DeepSeek-R1-Zero":
|
15 |
-
return demo_zero
|
16 |
-
else:
|
17 |
-
return demo_qwen # default fallback
|
18 |
-
|
19 |
-
# Title of the Streamlit app
|
20 |
-
st.title("DeepSeek Chatbot")
|
21 |
-
|
22 |
-
# Sidebar or main area for parameter selection
|
23 |
-
st.subheader("Model and Parameters")
|
24 |
-
|
25 |
-
model_name = st.selectbox(
|
26 |
-
"Select Model",
|
27 |
-
["DeepSeek-R1-Distill-Qwen-32B", "DeepSeek-R1", "DeepSeek-R1-Zero"]
|
28 |
-
)
|
29 |
-
|
30 |
-
# Optional parameter: System message
|
31 |
-
system_message = st.text_area(
|
32 |
-
"System Message",
|
33 |
-
value="You are a friendly Chatbot created by ruslanmv.com",
|
34 |
-
height=80
|
35 |
-
)
|
36 |
-
|
37 |
-
# Optional parameter: max new tokens
|
38 |
-
max_new_tokens = st.slider(
|
39 |
-
"Max new tokens",
|
40 |
-
min_value=1,
|
41 |
-
max_value=4000,
|
42 |
-
value=512,
|
43 |
-
step=1
|
44 |
-
)
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
-
"
|
49 |
-
|
50 |
-
|
51 |
-
value=0.80,
|
52 |
-
step=0.05
|
53 |
)
|
54 |
|
55 |
-
#
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
)
|
104 |
-
except Exception as e:
|
105 |
-
response = f"Error: {e}"
|
106 |
|
107 |
-
|
108 |
-
st.
|
109 |
-
|
110 |
-
|
111 |
-
#
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
else:
|
117 |
-
st.markdown(f"**{role}:** {text}")
|
118 |
-
|
|
|
1 |
# app.py
|
|
|
2 |
import streamlit as st
|
3 |
+
from models import demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Page configuration
|
6 |
+
st.set_page_config(
|
7 |
+
page_title="DeepSeek Chatbot - ruslanmv.com",
|
8 |
+
page_icon="🤖",
|
9 |
+
layout="centered"
|
|
|
|
|
10 |
)
|
11 |
|
12 |
+
# Initialize session state for chat history
|
13 |
+
if "messages" not in st.session_state:
|
14 |
+
st.session_state.messages = []
|
15 |
+
|
16 |
+
# Sidebar for model selection and parameters
|
17 |
+
with st.sidebar:
|
18 |
+
st.header("Model Configuration")
|
19 |
+
|
20 |
+
# Model selection
|
21 |
+
selected_model = st.selectbox(
|
22 |
+
"Choose Model",
|
23 |
+
[
|
24 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
25 |
+
"deepseek-ai/DeepSeek-R1",
|
26 |
+
"deepseek-ai/DeepSeek-R1-Zero"
|
27 |
+
],
|
28 |
+
index=0
|
29 |
+
)
|
30 |
+
|
31 |
+
# System message
|
32 |
+
system_message = st.text_area(
|
33 |
+
"System Message",
|
34 |
+
value="You are a friendly Chatbot created by ruslanmv.com",
|
35 |
+
height=100
|
36 |
+
)
|
37 |
+
|
38 |
+
# Generation parameters
|
39 |
+
max_tokens = st.slider(
|
40 |
+
"Max Tokens",
|
41 |
+
min_value=1,
|
42 |
+
max_value=4000,
|
43 |
+
value=512,
|
44 |
+
step=10
|
45 |
+
)
|
46 |
+
|
47 |
+
temperature = st.slider(
|
48 |
+
"Temperature",
|
49 |
+
min_value=0.1,
|
50 |
+
max_value=4.0,
|
51 |
+
value=0.7,
|
52 |
+
step=0.1
|
53 |
+
)
|
54 |
+
|
55 |
+
top_p = st.slider(
|
56 |
+
"Top-p (nucleus sampling)",
|
57 |
+
min_value=0.1,
|
58 |
+
max_value=1.0,
|
59 |
+
value=0.9,
|
60 |
+
step=0.1
|
61 |
+
)
|
62 |
+
|
63 |
+
# Main chat interface
|
64 |
+
st.title("🤖 DeepSeek Chatbot")
|
65 |
+
st.caption("Powered by ruslanmv.com - Choose your model and parameters in the sidebar")
|
66 |
+
|
67 |
+
# Display chat messages
|
68 |
+
for message in st.session_state.messages:
|
69 |
+
with st.chat_message(message["role"]):
|
70 |
+
st.markdown(message["content"])
|
71 |
+
|
72 |
+
# Chat input
|
73 |
+
if prompt := st.chat_input("Type your message..."):
|
74 |
+
# Add user message to chat history
|
75 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
76 |
+
|
77 |
+
# Display user message
|
78 |
+
with st.chat_message("user"):
|
79 |
+
st.markdown(prompt)
|
80 |
+
|
81 |
+
# Prepare full prompt with system message
|
82 |
+
full_prompt = f"{system_message}\n\nUser: {prompt}\nAssistant:"
|
83 |
+
|
84 |
+
try:
|
85 |
+
# Generate response using selected model
|
86 |
+
with st.spinner("Generating response..."):
|
87 |
+
# Updated parameter names to match model expectations
|
88 |
+
response = demo.fn(
|
89 |
+
full_prompt,
|
90 |
+
max_length=max_tokens, # Changed from max_new_tokens
|
91 |
+
temperature=temperature,
|
92 |
+
top_p=top_p
|
93 |
)
|
|
|
|
|
94 |
|
95 |
+
# Display assistant response
|
96 |
+
with st.chat_message("assistant"):
|
97 |
+
st.markdown(response)
|
98 |
+
|
99 |
+
# Add assistant response to chat history
|
100 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
101 |
+
|
102 |
+
except Exception as e:
|
103 |
+
st.error(f"Error generating response: {str(e)}")
|
|
|
|
|
|