Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,27 +64,39 @@ layer_agent_config_rec = {
|
|
| 64 |
|
| 65 |
def stream_response(messages: Iterable[ResponseChunk]):
|
| 66 |
layer_outputs = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
for message in messages:
|
|
|
|
|
|
|
|
|
|
| 68 |
if message['response_type'] == 'intermediate':
|
| 69 |
layer = message['metadata']['layer']
|
| 70 |
if layer not in layer_outputs:
|
| 71 |
layer_outputs[layer] = []
|
| 72 |
layer_outputs[layer].append(message['delta'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
else:
|
| 74 |
-
#
|
| 75 |
for layer, outputs in layer_outputs.items():
|
| 76 |
-
st.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
st.expander(label=f"Agent {i+1}", expanded=False).write(output)
|
| 81 |
-
|
| 82 |
-
# Clear layer outputs for the next iteration
|
| 83 |
-
layer_outputs = {}
|
| 84 |
|
| 85 |
# Yield the main agent's output
|
| 86 |
yield message['delta']
|
| 87 |
|
|
|
|
|
|
|
| 88 |
def set_moa_agent(
|
| 89 |
main_model: str = default_config['main_model'],
|
| 90 |
cycles: int = default_config['cycles'],
|
|
|
|
| 64 |
|
| 65 |
def stream_response(messages: Iterable[ResponseChunk]):
|
| 66 |
layer_outputs = {}
|
| 67 |
+
progress_bar = st.progress(0)
|
| 68 |
+
total_steps = len(messages) # Estimate total messages for progress tracking
|
| 69 |
+
current_step = 0
|
| 70 |
+
|
| 71 |
for message in messages:
|
| 72 |
+
current_step += 1
|
| 73 |
+
progress_bar.progress(current_step / total_steps)
|
| 74 |
+
|
| 75 |
if message['response_type'] == 'intermediate':
|
| 76 |
layer = message['metadata']['layer']
|
| 77 |
if layer not in layer_outputs:
|
| 78 |
layer_outputs[layer] = []
|
| 79 |
layer_outputs[layer].append(message['delta'])
|
| 80 |
+
|
| 81 |
+
# Real-time rendering for intermediate outputs
|
| 82 |
+
with st.container():
|
| 83 |
+
st.markdown(f"**Layer {layer} (In Progress)**")
|
| 84 |
+
for output in layer_outputs[layer]:
|
| 85 |
+
st.markdown(f"- {output}")
|
| 86 |
+
|
| 87 |
else:
|
| 88 |
+
# Finalize and display accumulated layer outputs
|
| 89 |
for layer, outputs in layer_outputs.items():
|
| 90 |
+
st.markdown(f"### Layer {layer} Final Output")
|
| 91 |
+
for output in outputs:
|
| 92 |
+
st.write(output)
|
| 93 |
+
layer_outputs = {} # Reset for next layers
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# Yield the main agent's output
|
| 96 |
yield message['delta']
|
| 97 |
|
| 98 |
+
progress_bar.empty() # Clear progress bar once done
|
| 99 |
+
|
| 100 |
def set_moa_agent(
|
| 101 |
main_model: str = default_config['main_model'],
|
| 102 |
cycles: int = default_config['cycles'],
|