Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +38 -24
src/streamlit_app.py
CHANGED
|
@@ -1,25 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
st.title("🤖 Chat con DeepSeek-R1")
|
| 5 |
+
|
| 6 |
+
API_KEY = st.secrets["OPENROUTER_API_KEY"]
|
| 7 |
+
|
| 8 |
+
if "messages" not in st.session_state:
|
| 9 |
+
st.session_state.messages = []
|
| 10 |
+
|
| 11 |
+
for msg in st.session_state.messages:
|
| 12 |
+
with st.chat_message(msg["role"]):
|
| 13 |
+
st.markdown(msg["content"])
|
| 14 |
+
|
| 15 |
+
prompt = st.chat_input("Escribe tu mensaje...")
|
| 16 |
+
|
| 17 |
+
if prompt:
|
| 18 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 19 |
+
with st.chat_message("user"):
|
| 20 |
+
st.markdown(prompt)
|
| 21 |
+
|
| 22 |
+
with st.chat_message("assistant"):
|
| 23 |
+
st.write("Pensando...")
|
| 24 |
+
|
| 25 |
+
response = requests.post(
|
| 26 |
+
"https://openrouter.ai/api/v1/chat/completions",
|
| 27 |
+
headers={
|
| 28 |
+
"Authorization": f"Bearer {API_KEY}",
|
| 29 |
+
"Content-Type": "application/json"
|
| 30 |
+
},
|
| 31 |
+
json={
|
| 32 |
+
"model": "deepseek/deepseek-r1:free",
|
| 33 |
+
"messages": st.session_state.messages
|
| 34 |
+
}
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
reply = response.json()["choices"][0]["message"]["content"]
|
| 38 |
+
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 39 |
+
st.experimental_rerun()
|