Home
from time import sleep
import mesop as me
def generate_str():
  yield "foo"
  sleep(1)
  yield "bar"
@me.stateclass
class State:
  string: str = ""
def button_click(action: me.ClickEvent):
  state = me.state(State)
  for val in generate_str():
    state.string += val
    yield
@me.page(path="/streaming")
def main():
  state = me.state(State)
  me.button("click", on_click=button_click)
  me.text(text=f"{state.string}")
@me.stateclass
class State:
    image_data: str
    detections: list[Detection]
@me.page()
def object_detector():
    state = me.state(State)
    me.text("Real-time Object Detection", type="headline-4")
    me.uploader(label="Upload an image", on_upload=on_image_upload)
    if state.image_data:
        me.image(src=f"data:image/jpeg;base64,{state.image_data}")
    if state.detections:
        me.text("Detected Objects:", type="headline-5")
        for detection in state.detections:
            detection_component(detection)
def detection_component(detection):
    me.text(f"{detection.obj}: {detection.confidence:.2f}")
def on_image_upload(e: me.UploadEvent):
    state = me.state(State)
    state.image_data = base64.b64encode(e.file.read()).decode()
    state.detections = detect_objects(e.file)
from typing import Any, Callable
import mesop as me
@me.web_component(path="./counter_component.js")
def counter_component(
  *,
  value: int,
  on_decrement: Callable[[me.WebEvent], Any],
  key: str | None = None,
):
  return me.insert_web_component(
    name="quickstart-counter-component",
    key=key,
    events={
      "decrementEvent": on_decrement,
    },
    properties={
      "value": value,
    },
  )
import {
  LitElement,
  html,
} from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
class CounterComponent extends LitElement {
  static properties = {
    value: {type: Number},
    decrementEvent: {type: String},
  };
  constructor() {
    super();
    this.value = 0;
    this.decrementEvent = '';
  }
  render() {
    return html`
      <div class="container">
        <span>Value: ${this.value}</span>
        <button id="decrement-btn" @click="${this._onDecrement}">
          Decrement
        </button>
      </div>
    `;
  }
  _onDecrement() {
    this.dispatchEvent(
      new MesopEvent(this.decrementEvent, {
        value: this.value - 1,
      }),
    );
  }
}
customElements.define('quickstart-counter-component', CounterComponent);
 
   
  is this the thing that will finally save me from ever learning front end?https://t.co/eDgY0AfG6U
— xlr8harder (@xlr8harder) June 6, 2024
i hate writing frontend code, but can’t resist a sleek UI. just tried Google’s quietly released Mesop—what a find! no frontend fuss, just python.
— Sanchay Thalnerkar (@7anchay) June 23, 2024
if you value your sanity and good design, you should def try it. gives a balance between streamlit and gradio
mesop docs :… pic.twitter.com/SmBAH5Leri
New Python-based UI framework in town - have you tried Mesop from Google?
— Harshit Tyagi (@dswharshit) June 11, 2024
I gave it a spin, here's what I found out:
📌 Provides a unique approach to building web hashtag#UIs in hashtag#Python with component-based architecture for customized UIs by taking inspiration from…
Disclaimer¶
This is not an officially supported Google product.