Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,39 +63,39 @@ layer_agent_config_rec = {
|
|
| 63 |
|
| 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 |
-
#
|
| 82 |
-
with st.container():
|
| 83 |
-
st.markdown(f"
|
| 84 |
for output in layer_outputs[layer]:
|
| 85 |
-
st.markdown(f"- {output}")
|
| 86 |
|
| 87 |
else:
|
| 88 |
-
#
|
| 89 |
for layer, outputs in layer_outputs.items():
|
| 90 |
st.markdown(f"### Layer {layer} Final Output")
|
| 91 |
for output in outputs:
|
| 92 |
-
st.
|
| 93 |
-
layer_outputs = {} # Reset for next layers
|
| 94 |
|
| 95 |
-
#
|
| 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'],
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
def stream_response(messages: Iterable[ResponseChunk]):
|
| 66 |
+
layer_outputs = {} # Store outputs per layer
|
| 67 |
+
progress_bar = st.progress(0) # Initialize progress bar
|
| 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) # Update progress bar
|
| 74 |
+
|
| 75 |
if message['response_type'] == 'intermediate':
|
| 76 |
+
layer = message['metadata']['layer'] # Identify the layer
|
| 77 |
if layer not in layer_outputs:
|
| 78 |
+
layer_outputs[layer] = [] # Initialize if layer not seen yet
|
| 79 |
+
layer_outputs[layer].append(message['delta']) # Add intermediate delta
|
| 80 |
|
| 81 |
+
# Render intermediate output in real-time
|
| 82 |
+
with st.container(): # Create a dynamic container for rendering
|
| 83 |
+
st.markdown(f"### Layer {layer} (In Progress)")
|
| 84 |
for output in layer_outputs[layer]:
|
| 85 |
+
st.markdown(f"- {output}") # Render each intermediate result
|
| 86 |
|
| 87 |
else:
|
| 88 |
+
# Final rendering of outputs after processing completes for this layer
|
| 89 |
for layer, outputs in layer_outputs.items():
|
| 90 |
st.markdown(f"### Layer {layer} Final Output")
|
| 91 |
for output in outputs:
|
| 92 |
+
st.markdown(f"- {output}")
|
|
|
|
| 93 |
|
| 94 |
+
layer_outputs = {} # Reset layer outputs for the next iteration
|
| 95 |
+
yield message['delta'] # Yield the final processed result
|
| 96 |
+
|
| 97 |
+
progress_bar.empty() # Clear progress bar after all processing is complete
|
| 98 |
|
|
|
|
| 99 |
|
| 100 |
def set_moa_agent(
|
| 101 |
main_model: str = default_config['main_model'],
|