Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
|
5 |
+
# Ollama API endpoint
|
6 |
+
OLLAMA_API_URL = "http://localhost:7860/api/chat" # Or your Ollama server address
|
7 |
+
|
8 |
+
# Streamlit UI
|
9 |
+
st.title("DeepSeek-R1 Chat")
|
10 |
+
|
11 |
+
# User prompt input
|
12 |
+
prompt = st.text_input("Enter your prompt:")
|
13 |
+
|
14 |
+
# Button to send the prompt
|
15 |
+
if st.button("Send"):
|
16 |
+
# Prepare the request data
|
17 |
+
data = {
|
18 |
+
"model": "deepseek-r1:7b",
|
19 |
+
"messages": [{"role": "user", "content": prompt}],
|
20 |
+
"stream": False
|
21 |
+
}
|
22 |
+
|
23 |
+
# Send the request to Ollama
|
24 |
+
try:
|
25 |
+
response = requests.post(OLLAMA_API_URL, data=json.dumps(data), headers={'Content-Type': 'application/json'})
|
26 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
27 |
+
response_data = response.json()
|
28 |
+
# Extract the model's response
|
29 |
+
model_response = response_data['message']['content']
|
30 |
+
st.write(f"**Model:** {model_response}")
|
31 |
+
|
32 |
+
except requests.exceptions.RequestException as e:
|
33 |
+
st.error(f"Error: {e}")
|