Spaces:
Sleeping
Sleeping
Commit
Β·
d0a7f23
1
Parent(s):
e29e6f4
deepseek hf
Browse files- README.md +12 -0
- app.py +54 -0
- requirements.txt +2 -0
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Deepseek Chat
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.41.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: deepseek chat - huggingface api
|
| 12 |
+
---
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
# Streamlit UI
|
| 5 |
+
st.title("π³ Chat with DeepSeek π³")
|
| 6 |
+
|
| 7 |
+
with st.sidebar:
|
| 8 |
+
# Input box for user to enter their Hugging Face API key
|
| 9 |
+
api_key = st.text_input("Enter your Hugging Face API Key:", type="password")
|
| 10 |
+
|
| 11 |
+
if api_key:
|
| 12 |
+
# Initialize the InferenceClient with the user-provided API key
|
| 13 |
+
client = InferenceClient(api_key=api_key)
|
| 14 |
+
|
| 15 |
+
# Input box for user to enter their question
|
| 16 |
+
user_input = st.chat_input("Enter your question:")
|
| 17 |
+
|
| 18 |
+
if user_input:
|
| 19 |
+
# Prepare the messages for the model
|
| 20 |
+
messages = [
|
| 21 |
+
{
|
| 22 |
+
"role": "user",
|
| 23 |
+
"content": user_input
|
| 24 |
+
}
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
# Get the completion from the model
|
| 28 |
+
completion = client.chat.completions.create(
|
| 29 |
+
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 30 |
+
messages=messages,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Get the model's response
|
| 34 |
+
response = completion.choices[0].message['content']
|
| 35 |
+
|
| 36 |
+
# Check if the response contains <think> tags
|
| 37 |
+
if "<think>" in response and "</think>" in response:
|
| 38 |
+
# Extract content within <think> tags
|
| 39 |
+
think_content = response.split("<think>")[1].split("</think>")[0].strip()
|
| 40 |
+
# Display the thinking content in an expander
|
| 41 |
+
with st.expander("Thinking..."):
|
| 42 |
+
st.write(think_content)
|
| 43 |
+
|
| 44 |
+
# Extract the rest of the response (outside <think> tags)
|
| 45 |
+
rest_of_response = response.split("</think>")[1].strip()
|
| 46 |
+
# Display the rest of the response with an AI icon
|
| 47 |
+
with st.chat_message("ai"):
|
| 48 |
+
st.write(rest_of_response)
|
| 49 |
+
else:
|
| 50 |
+
# If no <think> tags, display the entire response with an AI icon
|
| 51 |
+
with st.chat_message("ai"):
|
| 52 |
+
st.write(rest_of_response)
|
| 53 |
+
else:
|
| 54 |
+
st.warning("Please enter your Hugging Face API Key to proceed.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
huggingface-hub
|