Skip to content

Update app.py #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions loader-animation/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ async def send_animated_message(
except asyncio.CancelledError:
msg.content = base_msg
await msg.update() # Final static message
base_msg: str,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was the older body of the function that got left behind

frames: List[str],
interval: float = 0.8
) -> None:
"""Display animated message with minimal resource usage"""
msg = cl.Message(content=base_msg)
await msg.send()

progress = 0
bar_length = 12 # Optimal length for progress bar

try:
while True:
# Efficient progress calculation
current_frame = frames[progress % len(frames)]
progress_bar = ("▣" * (progress % bar_length)).ljust(bar_length, "▢")

# Single update operation
await msg.update(content=f"{current_frame} {base_msg}\n{progress_bar}")

progress += 1
await asyncio.sleep(interval)
except asyncio.CancelledError:
await msg.update(content=base_msg) # Final static message

@cl.on_message
async def main(message: cl.Message) -> None:
Expand All @@ -76,4 +52,4 @@ async def main(message: cl.Message) -> None:

await cl.Message(content="Done!").send()
else:
await cl.Message(content="Send 'test animation'").send()
await cl.Message(content="Send 'test animation'").send()