Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
# Hugging Face API URL
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
|
| 6 |
|
| 7 |
# Function to query the Hugging Face API
|
| 8 |
-
def query(payload):
|
| 9 |
headers = {"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"}
|
| 10 |
-
response = requests.post(
|
| 11 |
return response.json()
|
| 12 |
|
| 13 |
# Page configuration
|
|
@@ -26,6 +26,14 @@ with st.sidebar:
|
|
| 26 |
st.header("Model Configuration")
|
| 27 |
st.markdown("[Get HuggingFace Token](https://huggingface.co/settings/tokens)")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
system_message = st.text_area(
|
| 30 |
"System Message",
|
| 31 |
value="You are a friendly Chatbot created by ruslanmv.com",
|
|
@@ -76,15 +84,15 @@ if prompt := st.chat_input("Type your message..."):
|
|
| 76 |
}
|
| 77 |
}
|
| 78 |
|
| 79 |
-
# Query the Hugging Face API
|
| 80 |
-
output = query(payload)
|
| 81 |
|
| 82 |
# Handle API response
|
| 83 |
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
| 84 |
assistant_response = output[0]['generated_text']
|
| 85 |
else:
|
| 86 |
st.error("Error: Unable to generate a response. Please try again.")
|
| 87 |
-
|
| 88 |
|
| 89 |
with st.chat_message("assistant"):
|
| 90 |
st.markdown(assistant_response)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
|
| 4 |
+
# Hugging Face API URL (default model)
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
|
| 6 |
|
| 7 |
# Function to query the Hugging Face API
|
| 8 |
+
def query(payload, api_url):
|
| 9 |
headers = {"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"}
|
| 10 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 11 |
return response.json()
|
| 12 |
|
| 13 |
# Page configuration
|
|
|
|
| 26 |
st.header("Model Configuration")
|
| 27 |
st.markdown("[Get HuggingFace Token](https://huggingface.co/settings/tokens)")
|
| 28 |
|
| 29 |
+
# Dropdown to select model
|
| 30 |
+
model_options = [
|
| 31 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 32 |
+
"deepseek-ai/DeepSeek-R1",
|
| 33 |
+
"deepseek-ai/DeepSeek-R1-Zero"
|
| 34 |
+
]
|
| 35 |
+
selected_model = st.selectbox("Select Model", model_options, index=0)
|
| 36 |
+
|
| 37 |
system_message = st.text_area(
|
| 38 |
"System Message",
|
| 39 |
value="You are a friendly Chatbot created by ruslanmv.com",
|
|
|
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
+
# Query the Hugging Face API using the selected model
|
| 88 |
+
output = query(payload, f"https://api-inference.huggingface.co/models/{selected_model}")
|
| 89 |
|
| 90 |
# Handle API response
|
| 91 |
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
| 92 |
assistant_response = output[0]['generated_text']
|
| 93 |
else:
|
| 94 |
st.error("Error: Unable to generate a response. Please try again.")
|
| 95 |
+
continue # Skip further execution for this iteration
|
| 96 |
|
| 97 |
with st.chat_message("assistant"):
|
| 98 |
st.markdown(assistant_response)
|