multiapi / streamlit_app.py
Juna190825's picture
Update streamlit_app.py
01a0232 verified
raw
history blame
1.11 kB
import streamlit as st
import httpx
import os
# Set Streamlit config directory to a writable location
os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
st.set_page_config(page_title="OpenRouter Chat", layout="wide")
st.title("🧠 OpenRouter Chat Interface")
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
user_input = st.chat_input("Type your message...")
if user_input:
st.session_state.chat_history.append(("user", user_input))
with st.spinner("Thinking..."):
try:
response = httpx.post(
"http://localhost:7860/query",
data={"prompt": user_input}
)
if response.status_code == 200:
reply = response.json().get("response", "No response received.")
else:
reply = f"Error: {response.status_code} - {response.text}"
except Exception as e:
reply = f"Exception occurred: {e}"
st.session_state.chat_history.append(("bot", reply))
for role, msg in st.session_state.chat_history:
st.chat_message(role).write(msg)