Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -181,6 +181,16 @@ def get_stats():
|
|
181 |
"dataset_name": DATASET_NAME
|
182 |
}
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
# Create a Stanford theme
|
185 |
theme = gr.themes.Default(
|
186 |
primary_hue=gr.themes.utils.colors.red,
|
@@ -215,6 +225,9 @@ css = """
|
|
215 |
|
216 |
# Set up the Gradio app with Blocks for more control
|
217 |
with gr.Blocks(theme=theme, title="Stanford Soft Raccoon Chat", css=css) as demo:
|
|
|
|
|
|
|
218 |
with gr.Row():
|
219 |
with gr.Column(scale=3):
|
220 |
# Create the chatbot component directly
|
@@ -242,14 +255,6 @@ with gr.Blocks(theme=theme, title="Stanford Soft Raccoon Chat", css=css) as demo
|
|
242 |
label="Top-P"
|
243 |
)
|
244 |
|
245 |
-
# Create the ChatInterface with properly formatted examples
|
246 |
-
# Each example is a list: [message, temperature, top_p]
|
247 |
-
examples_with_params = [
|
248 |
-
["Tell me about Stanford University", 0.7, 0.9],
|
249 |
-
["How can I learn about artificial intelligence?", 0.8, 0.95],
|
250 |
-
["What's your favorite book?", 0.6, 0.85]
|
251 |
-
]
|
252 |
-
|
253 |
# Create the ChatInterface
|
254 |
chat_interface = gr.ChatInterface(
|
255 |
fn=chat_model,
|
@@ -258,7 +263,11 @@ with gr.Blocks(theme=theme, title="Stanford Soft Raccoon Chat", css=css) as demo
|
|
258 |
type="messages", # This is important for compatibility
|
259 |
title="Stanford Soft Raccoon Chat",
|
260 |
description="AI assistant powered by the Soft Raccoon language model",
|
261 |
-
examples=
|
|
|
|
|
|
|
|
|
262 |
cache_examples=True,
|
263 |
)
|
264 |
|
@@ -284,27 +293,24 @@ with gr.Blocks(theme=theme, title="Stanford Soft Raccoon Chat", css=css) as demo
|
|
284 |
[status_output]
|
285 |
)
|
286 |
|
287 |
-
def update_stats():
|
288 |
-
stats = get_stats()
|
289 |
-
return [
|
290 |
-
stats["conversation_count"],
|
291 |
-
stats["next_save"],
|
292 |
-
stats["last_save"],
|
293 |
-
stats["dataset_name"]
|
294 |
-
]
|
295 |
-
|
296 |
refresh_btn.click(
|
297 |
-
|
298 |
[],
|
299 |
[convo_count, next_save, last_save_time_display, dataset_name_display]
|
300 |
)
|
301 |
|
302 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
demo.load(
|
304 |
-
|
305 |
-
[],
|
306 |
-
[convo_count, next_save, last_save_time_display, dataset_name_display]
|
307 |
-
every=30 # Refresh every 30 seconds
|
308 |
)
|
309 |
|
310 |
# Ensure we save on shutdown
|
@@ -313,4 +319,5 @@ with gr.Blocks(theme=theme, title="Stanford Soft Raccoon Chat", css=css) as demo
|
|
313 |
|
314 |
# Launch the app
|
315 |
if __name__ == "__main__":
|
|
|
316 |
demo.launch(share=True)
|
|
|
181 |
"dataset_name": DATASET_NAME
|
182 |
}
|
183 |
|
184 |
+
def update_stats_event():
|
185 |
+
"""Update the stats UI elements"""
|
186 |
+
stats = get_stats()
|
187 |
+
return [
|
188 |
+
stats["conversation_count"],
|
189 |
+
stats["next_save"],
|
190 |
+
stats["last_save"],
|
191 |
+
stats["dataset_name"]
|
192 |
+
]
|
193 |
+
|
194 |
# Create a Stanford theme
|
195 |
theme = gr.themes.Default(
|
196 |
primary_hue=gr.themes.utils.colors.red,
|
|
|
225 |
|
226 |
# Set up the Gradio app with Blocks for more control
|
227 |
with gr.Blocks(theme=theme, title="Stanford Soft Raccoon Chat", css=css) as demo:
|
228 |
+
# Create a timer for periodic updates
|
229 |
+
timer = gr.Timer(30, update_stats_event) # Update every 30 seconds
|
230 |
+
|
231 |
with gr.Row():
|
232 |
with gr.Column(scale=3):
|
233 |
# Create the chatbot component directly
|
|
|
255 |
label="Top-P"
|
256 |
)
|
257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
# Create the ChatInterface
|
259 |
chat_interface = gr.ChatInterface(
|
260 |
fn=chat_model,
|
|
|
263 |
type="messages", # This is important for compatibility
|
264 |
title="Stanford Soft Raccoon Chat",
|
265 |
description="AI assistant powered by the Soft Raccoon language model",
|
266 |
+
examples=[
|
267 |
+
["Tell me about Stanford University", 0.7, 0.9],
|
268 |
+
["How can I learn about artificial intelligence?", 0.8, 0.95],
|
269 |
+
["What's your favorite book?", 0.6, 0.85]
|
270 |
+
],
|
271 |
cache_examples=True,
|
272 |
)
|
273 |
|
|
|
293 |
[status_output]
|
294 |
)
|
295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
refresh_btn.click(
|
297 |
+
update_stats_event,
|
298 |
[],
|
299 |
[convo_count, next_save, last_save_time_display, dataset_name_display]
|
300 |
)
|
301 |
|
302 |
+
# Connect the timer to update the stats displays
|
303 |
+
timer.stream(
|
304 |
+
fn=lambda: None, # No-op function
|
305 |
+
inputs=None,
|
306 |
+
outputs=None,
|
307 |
+
)
|
308 |
+
|
309 |
+
# Initial update of stats on page load
|
310 |
demo.load(
|
311 |
+
update_stats_event,
|
312 |
+
[],
|
313 |
+
[convo_count, next_save, last_save_time_display, dataset_name_display]
|
|
|
314 |
)
|
315 |
|
316 |
# Ensure we save on shutdown
|
|
|
319 |
|
320 |
# Launch the app
|
321 |
if __name__ == "__main__":
|
322 |
+
demo.queue() # Enable queuing for better performance
|
323 |
demo.launch(share=True)
|