Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,6 @@
|
|
| 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
|
| 14 |
st.set_page_config(
|
| 15 |
page_title="DeepSeek Chatbot - ruslanmv.com",
|
|
@@ -55,6 +46,12 @@ with st.sidebar:
|
|
| 55 |
0.1, 1.0, 0.9
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Chat interface
|
| 59 |
st.title("🤖 DeepSeek Chatbot")
|
| 60 |
st.caption("Powered by Hugging Face Inference API - Configure in sidebar")
|
|
@@ -84,8 +81,11 @@ if prompt := st.chat_input("Type your message..."):
|
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
|
|
|
|
|
|
|
|
|
| 87 |
# Query the Hugging Face API using the selected model
|
| 88 |
-
output = query(payload,
|
| 89 |
|
| 90 |
# Handle API response
|
| 91 |
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
|
@@ -99,4 +99,4 @@ if prompt := st.chat_input("Type your message..."):
|
|
| 99 |
st.error("Error: Unable to generate a response. Please try again.")
|
| 100 |
|
| 101 |
except Exception as e:
|
| 102 |
-
st.error(f"Application Error: {str(e)}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Page configuration
|
| 5 |
st.set_page_config(
|
| 6 |
page_title="DeepSeek Chatbot - ruslanmv.com",
|
|
|
|
| 46 |
0.1, 1.0, 0.9
|
| 47 |
)
|
| 48 |
|
| 49 |
+
# Function to query the Hugging Face API
|
| 50 |
+
def query(payload, api_url):
|
| 51 |
+
headers = {"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"}
|
| 52 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 53 |
+
return response.json()
|
| 54 |
+
|
| 55 |
# Chat interface
|
| 56 |
st.title("🤖 DeepSeek Chatbot")
|
| 57 |
st.caption("Powered by Hugging Face Inference API - Configure in sidebar")
|
|
|
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
+
# Dynamically construct the API URL based on the selected model
|
| 85 |
+
api_url = f"https://api-inference.huggingface.co/models/{selected_model}"
|
| 86 |
+
|
| 87 |
# Query the Hugging Face API using the selected model
|
| 88 |
+
output = query(payload, api_url)
|
| 89 |
|
| 90 |
# Handle API response
|
| 91 |
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
|
|
|
| 99 |
st.error("Error: Unable to generate a response. Please try again.")
|
| 100 |
|
| 101 |
except Exception as e:
|
| 102 |
+
st.error(f"Application Error: {str(e)}")
|