Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +17 -9
streamlit_app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import httpx
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="OpenRouter Chat", layout="wide")
|
| 5 |
st.title("🧠 OpenRouter Chat Interface")
|
|
@@ -12,15 +16,19 @@ user_input = st.chat_input("Type your message...")
|
|
| 12 |
if user_input:
|
| 13 |
st.session_state.chat_history.append(("user", user_input))
|
| 14 |
with st.spinner("Thinking..."):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
st.session_state.chat_history.append(("bot", reply))
|
| 21 |
|
| 22 |
for role, msg in st.session_state.chat_history:
|
| 23 |
-
|
| 24 |
-
st.chat_message("user").write(msg)
|
| 25 |
-
else:
|
| 26 |
-
st.chat_message("assistant").write(msg)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import httpx
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Set Streamlit config directory to a writable location
|
| 6 |
+
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
|
| 7 |
|
| 8 |
st.set_page_config(page_title="OpenRouter Chat", layout="wide")
|
| 9 |
st.title("🧠 OpenRouter Chat Interface")
|
|
|
|
| 16 |
if user_input:
|
| 17 |
st.session_state.chat_history.append(("user", user_input))
|
| 18 |
with st.spinner("Thinking..."):
|
| 19 |
+
try:
|
| 20 |
+
response = httpx.post(
|
| 21 |
+
"http://localhost:7860/query",
|
| 22 |
+
data={"prompt": user_input}
|
| 23 |
+
)
|
| 24 |
+
if response.status_code == 200:
|
| 25 |
+
reply = response.json().get("response", "No response received.")
|
| 26 |
+
else:
|
| 27 |
+
reply = f"Error: {response.status_code} - {response.text}"
|
| 28 |
+
except Exception as e:
|
| 29 |
+
reply = f"Exception occurred: {e}"
|
| 30 |
+
|
| 31 |
st.session_state.chat_history.append(("bot", reply))
|
| 32 |
|
| 33 |
for role, msg in st.session_state.chat_history:
|
| 34 |
+
st.chat_message(role).write(msg)
|
|
|
|
|
|
|
|
|