ruslanmv commited on
Commit
804d0d3
·
verified ·
1 Parent(s): 94d49c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -108
app.py CHANGED
@@ -26,8 +26,10 @@ with st.sidebar:
26
  # Dropdown to select model
27
  model_options = [
28
  "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
29
- "deepseek-ai/DeepSeek-R1",
30
- "deepseek-ai/DeepSeek-R1-Zero"
 
 
31
  ]
32
  selected_model = st.selectbox("Select Model", model_options, index=0)
33
 
@@ -113,109 +115,3 @@ if prompt := st.chat_input("Type your message..."):
113
  logger.error(f"Application Error: {str(e)}", exc_info=True)
114
  st.error(f"Application Error: {str(e)}")
115
 
116
-
117
- ''''
118
- import streamlit as st
119
- import requests
120
-
121
- # Page configuration
122
- st.set_page_config(
123
- page_title="DeepSeek Chatbot - ruslanmv.com",
124
- page_icon="🤖",
125
- layout="centered"
126
- )
127
-
128
- # Initialize session state for chat history
129
- if "messages" not in st.session_state:
130
- st.session_state.messages = []
131
-
132
- # Sidebar configuration
133
- with st.sidebar:
134
- st.header("Model Configuration")
135
- st.markdown("[Get HuggingFace Token](https://huggingface.co/settings/tokens)")
136
-
137
- # Dropdown to select model
138
- model_options = [
139
- "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
140
- "deepseek-ai/DeepSeek-R1",
141
- "deepseek-ai/DeepSeek-R1-Zero"
142
- ]
143
- selected_model = st.selectbox("Select Model", model_options, index=0)
144
-
145
- system_message = st.text_area(
146
- "System Message",
147
- value="You are a friendly Chatbot created by ruslanmv.com",
148
- height=100
149
- )
150
-
151
- max_tokens = st.slider(
152
- "Max Tokens",
153
- 1, 4000, 512
154
- )
155
-
156
- temperature = st.slider(
157
- "Temperature",
158
- 0.1, 4.0, 0.7
159
- )
160
-
161
- top_p = st.slider(
162
- "Top-p",
163
- 0.1, 1.0, 0.9
164
- )
165
-
166
- # Function to query the Hugging Face API
167
- def query(payload, api_url):
168
- headers = {"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"}
169
- response = requests.post(api_url, headers=headers, json=payload)
170
- return response.json()
171
-
172
- # Chat interface
173
- st.title("🤖 DeepSeek Chatbot")
174
- st.caption("Powered by Hugging Face Inference API - Configure in sidebar")
175
-
176
- # Display chat history
177
- for message in st.session_state.messages:
178
- with st.chat_message(message["role"]):
179
- st.markdown(message["content"])
180
-
181
- # Handle input
182
- if prompt := st.chat_input("Type your message..."):
183
- st.session_state.messages.append({"role": "user", "content": prompt})
184
-
185
- with st.chat_message("user"):
186
- st.markdown(prompt)
187
-
188
- try:
189
- with st.spinner("Generating response..."):
190
- # Prepare the payload for the API
191
- payload = {
192
- "inputs": prompt,
193
- "parameters": {
194
- "max_new_tokens": max_tokens,
195
- "temperature": temperature,
196
- "top_p": top_p,
197
- "return_full_text": False
198
- }
199
- }
200
-
201
- # Dynamically construct the API URL based on the selected model
202
- api_url = f"https://api-inference.huggingface.co/models/{selected_model}"
203
-
204
- # Query the Hugging Face API using the selected model
205
- output = query(payload, api_url)
206
-
207
- # Handle API response
208
- if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
209
- assistant_response = output[0]['generated_text']
210
-
211
- with st.chat_message("assistant"):
212
- st.markdown(assistant_response)
213
-
214
- st.session_state.messages.append({"role": "assistant", "content": assistant_response})
215
- else:
216
- st.error("Error: Unable to generate a response. Please try again.")
217
-
218
- except Exception as e:
219
- st.error(f"Application Error: {str(e)}")
220
-
221
- '''
 
26
  # Dropdown to select model
27
  model_options = [
28
  "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
29
+ "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
30
+ "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
31
+ "deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
32
+ "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
33
  ]
34
  selected_model = st.selectbox("Select Model", model_options, index=0)
35
 
 
115
  logger.error(f"Application Error: {str(e)}", exc_info=True)
116
  st.error(f"Application Error: {str(e)}")
117