google / mesop

Rapidly build AI apps in Python
https://google.github.io/mesop/
Apache License 2.0
5.63k stars 270 forks source link

Streaming UI doesn't work in Colab #594

Open wwwillchen opened 4 months ago

wwwillchen commented 4 months ago

Repro: use demo/chat.py in colab:

import random
import time

import mesop as me
import mesop.labs as mel

me.colab_run()

@me.page(
  security_policy=me.SecurityPolicy(
    allowed_iframe_parents=["https://google.github.io"]
  ),
  path="/chat",
  title="Mesop Demo Chat",
)
def page():
  mel.chat(transform, title="Mesop Demo Chat", bot_user="Mesop Bot")

def transform(input: str, history: list[mel.ChatMessage]):
  for line in random.sample(LINES, random.randint(3, len(LINES) - 1)):
    time.sleep(0.3)
    yield line + " "

LINES = [
  "Mesop is a Python-based UI framework designed to simplify web UI development for engineers without frontend experience.",
  "It leverages the power of the Angular web framework and Angular Material components, allowing rapid construction of web demos and internal tools.",
  "With Mesop, developers can enjoy a fast build-edit-refresh loop thanks to its hot reload feature, making UI tweaks and component integration seamless.",
  "Deployment is straightforward, utilizing standard HTTP technologies.",
  "Mesop's component library aims for comprehensive Angular Material component coverage, enhancing UI flexibility and composability.",
  "It supports custom components for specific use cases, ensuring developers can extend its capabilities to fit their unique requirements.",
  "Mesop's roadmap includes expanding its component library and simplifying the onboarding processs.",
]

me.colab_show(path="/chat")

However, streaming UI does work properly outside of Colab (e.g. locally, Cloud Run) so there must be something unusual happening when Colab is executing the code.

Yash-Kavaiya commented 3 months ago

@wwwillchen This Colab Run on Google machine So if you request from outside Colab you need to do tunning for access this you can use ngrok for tunning