Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,9 @@ def load_data():
|
|
39 |
st.session_state.users = []
|
40 |
|
41 |
# Load data at the start
|
42 |
-
|
|
|
|
|
43 |
|
44 |
# Function to get or create user
|
45 |
def get_or_create_user():
|
@@ -100,7 +102,7 @@ with st.sidebar:
|
|
100 |
st.session_state.current_user['name'] = new_name
|
101 |
save_data()
|
102 |
st.success(f"Name updated to {new_name}")
|
103 |
-
|
104 |
|
105 |
st.title("Active Users")
|
106 |
for user in st.session_state.users:
|
@@ -110,47 +112,42 @@ with st.sidebar:
|
|
110 |
st.title("Personalized Real-Time Chat with ArXiv Search")
|
111 |
|
112 |
# Display chat messages
|
113 |
-
|
|
|
|
|
114 |
|
115 |
# Input for new message
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
st.
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
})
|
136 |
-
|
137 |
-
save_data()
|
138 |
-
st.experimental_rerun()
|
139 |
-
|
140 |
-
# Function to display chat messages
|
141 |
-
def display_messages():
|
142 |
-
for msg in st.session_state.messages:
|
143 |
-
with chat_container.container():
|
144 |
-
st.write(f"**{msg['user']}** ({msg['timestamp']}): {msg['message']}")
|
145 |
|
146 |
-
|
147 |
-
|
148 |
|
149 |
# Polling for updates
|
150 |
if st.button("Refresh Chat"):
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
153 |
|
154 |
-
|
155 |
-
time.
|
156 |
-
st.
|
|
|
39 |
st.session_state.users = []
|
40 |
|
41 |
# Load data at the start
|
42 |
+
if 'data_loaded' not in st.session_state:
|
43 |
+
load_data()
|
44 |
+
st.session_state.data_loaded = True
|
45 |
|
46 |
# Function to get or create user
|
47 |
def get_or_create_user():
|
|
|
102 |
st.session_state.current_user['name'] = new_name
|
103 |
save_data()
|
104 |
st.success(f"Name updated to {new_name}")
|
105 |
+
st.rerun()
|
106 |
|
107 |
st.title("Active Users")
|
108 |
for user in st.session_state.users:
|
|
|
112 |
st.title("Personalized Real-Time Chat with ArXiv Search")
|
113 |
|
114 |
# Display chat messages
|
115 |
+
for message in st.session_state.messages:
|
116 |
+
with st.chat_message(message["role"]):
|
117 |
+
st.markdown(message["content"])
|
118 |
|
119 |
# Input for new message
|
120 |
+
if prompt := st.chat_input("Type your message or ArXiv search query:"):
|
121 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
122 |
+
with st.chat_message("user"):
|
123 |
+
st.markdown(prompt)
|
124 |
+
|
125 |
+
# Check if it's an ArXiv search query
|
126 |
+
if prompt.lower().startswith("arxiv:"):
|
127 |
+
query = prompt[6:].strip()
|
128 |
+
with st.chat_message("assistant"):
|
129 |
+
with st.spinner("Searching ArXiv..."):
|
130 |
+
search_results = search_arxiv(query)
|
131 |
+
st.markdown(f"Search results for '{query}':\n\n{search_results}")
|
132 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Search results for '{query}':\n\n{search_results}"})
|
133 |
+
else:
|
134 |
+
# Here you would typically send the message to your chat model and get a response
|
135 |
+
# For this example, we'll just echo the message
|
136 |
+
with st.chat_message("assistant"):
|
137 |
+
st.markdown(f"You said: {prompt}")
|
138 |
+
st.session_state.messages.append({"role": "assistant", "content": f"You said: {prompt}"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
save_data()
|
141 |
+
st.rerun()
|
142 |
|
143 |
# Polling for updates
|
144 |
if st.button("Refresh Chat"):
|
145 |
+
st.rerun()
|
146 |
+
|
147 |
+
# Auto-refresh
|
148 |
+
if 'last_refresh' not in st.session_state:
|
149 |
+
st.session_state.last_refresh = time.time()
|
150 |
|
151 |
+
if time.time() - st.session_state.last_refresh > 5: # Refresh every 5 seconds
|
152 |
+
st.session_state.last_refresh = time.time()
|
153 |
+
st.rerun()
|