Skip to content
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

Support JupyterLab #354

Closed
wwwillchen opened this issue Jun 5, 2024 · 2 comments · Fixed by #615
Closed

Support JupyterLab #354

wwwillchen opened this issue Jun 5, 2024 · 2 comments · Fixed by #615
Assignees
Labels
feature request New feature / API votes needed waiting for community to upvote issue

Comments

@wwwillchen
Copy link
Collaborator

Source: https://www.reddit.com/r/LocalLLaMA/comments/1d8g5j1/comment/l76huu2/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

@wwwillchen wwwillchen added votes needed waiting for community to upvote issue feature request New feature / API labels Jun 19, 2024
@rezpe
Copy link

rezpe commented Jun 22, 2024

This would be great if it worked on jupyter. After reviewing the colab folder, it seems we need to implement 2 functions: jupyter_run and jupyter_show. That could be a direction for it:

import threading

from absl import flags  # Keep this for flag handling if needed
from mesop.runtime import enable_debug_mode 
from mesop.server.constants import EDITOR_PACKAGE_PATH, PROD_PACKAGE_PATH
from mesop.server.logging import log_startup
from mesop.server.server import configure_flask_app
from mesop.server.static_file_serving import configure_static_file_serving

def jupyter_run(port: int = 32123, prod_mode: bool = False):
  """Starts the Mesop web server. 
  """

  # Flag handling (adapt as needed for your application)
  if not flags.FLAGS.is_parsed():
    flags.FLAGS.mark_as_parsed() 

  flask_app = configure_flask_app(prod_mode=prod_mode)
  if not prod_mode:
    enable_debug_mode()

  configure_static_file_serving(
      flask_app,
      static_file_runfiles_base=PROD_PACKAGE_PATH 
      if prod_mode
      else EDITOR_PACKAGE_PATH,
  )

  log_startup(port=port)

  def run_flask():
      print(f" * Running Mesop app on http://localhost:{port}/") # Print URL
      flask_app.run(host="::", port=port, use_reloader=False)


import threading
import time
from IPython.display import IFrame, display 

# ... (Your existing Flask app setup code) ...

def jupyter_show(port: int = 32123, path: str = "/", width: str = "100%", height: str = "400"):
    """Displays the Mesop app in a JupyterLab cell output as an IFrame."""

    def show_iframe():
        """Displays the IFrame after a short delay to ensure the server is running."""
        time.sleep(2)  # Adjust delay if needed 
        display(IFrame(src=f"http://localhost:{port}{path}", width=width, height=height))

    # Run the iframe display function in a separate thread
    threading.Thread(target=show_iframe).start()

@wwwillchen , what do you think ?

@wwwillchen wwwillchen self-assigned this Jun 24, 2024
@wwwillchen
Copy link
Collaborator Author

Thanks, I'll take a look and try your suggestion out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature / API votes needed waiting for community to upvote issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants