Spaces:
Sleeping
Sleeping
Create streamlit_app.py
Browse files- streamlit_app.py +26 -0
streamlit_app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|
| 6 |
+
|
| 7 |
+
if "chat_history" not in st.session_state:
|
| 8 |
+
st.session_state.chat_history = []
|
| 9 |
+
|
| 10 |
+
user_input = st.chat_input("Type your message...")
|
| 11 |
+
|
| 12 |
+
if user_input:
|
| 13 |
+
st.session_state.chat_history.append(("user", user_input))
|
| 14 |
+
with st.spinner("Thinking..."):
|
| 15 |
+
response = httpx.post(
|
| 16 |
+
"http://localhost:7860/query",
|
| 17 |
+
data={"prompt": user_input}
|
| 18 |
+
)
|
| 19 |
+
reply = response.json()["response"]
|
| 20 |
+
st.session_state.chat_history.append(("bot", reply))
|
| 21 |
+
|
| 22 |
+
for role, msg in st.session_state.chat_history:
|
| 23 |
+
if role == "user":
|
| 24 |
+
st.chat_message("user").write(msg)
|
| 25 |
+
else:
|
| 26 |
+
st.chat_message("assistant").write(msg)
|