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

Using heartrate on Google Colaboratory ? #7

Open
jbdatascience opened this issue Apr 30, 2021 · 8 comments
Open

Using heartrate on Google Colaboratory ? #7

jbdatascience opened this issue Apr 30, 2021 · 8 comments

Comments

@jbdatascience
Copy link

Having read the article https://towardsdatascience.com/3-tools-to-track-and-visualize-the-execution-of-your-python-code-666a153e435e, I was wondering on how to use heartrate on Google Colaboratory?
Is this possible and if yes: how exactly to that.

@alexmojaki
Copy link
Owner

Take a look at https://stackoverflow.com/questions/54465816/how-to-use-flask-in-google-colaboratory-python-notebook. Based on the first answer you could get the IP of the notebook with print(socket.gethostbyname(socket.getfqdn(socket.gethostname()))) and use trace(host='0.0.0.0') to make heartrate accessible remotely. Does that work?

@jbdatascience
Copy link
Author

Take a look at https://stackoverflow.com/questions/54465816/how-to-use-flask-in-google-colaboratory-python-notebook. Based on the first answer you could get the IP of the notebook with print(socket.gethostbyname(socket.getfqdn(socket.gethostname()))) and use trace(host='0.0.0.0') to make heartrate accessible remotely. Does that work?

I have no experience with Flask, so this is a good time to give it a try !

I got the LAST example from
https://stackoverflow.com/questions/54465816/how-to-use-flask-in-google-colaboratory-python-notebookworking
working in COLAB !

But what exactly should I use as the "server side code AKA: backend" code for the factorial example from your article:

import heartrate
from time import sleep

heartrate.trace(browser=True)

def factorial(x):
if x == 1:
return 1
else:
sleep(0.5)
return (x * factorial(x-1))

if name == "main":
num = 20
print(f"The factorial of {num} is {factorial(num)}")

@alexmojaki
Copy link
Owner

Use heartrate.trace(host='0.0.0.0') and port 9999 in the client side.

@jbdatascience
Copy link
Author

Use heartrate.trace(host='0.0.0.0') and port 9999 in the client side.

This is a COLAB Notebook that works with a demo Flasjk app:
https://colab.research.google.com/drive/1ocoD0B0h2F8HhwWz9j9Td4uhvoTk_Um2#scrollTo=lrO47YxeJzTl

How do I convert that, so that it runs the factorial example ?

@alexmojaki
Copy link
Owner

Welp, I tried, couldn't get anything to work. If I run heartrate on port 80 and then point ngrok to port 80 I get close, but I get a 404. Seems to have to do with the SERVER_NAME config but setting it to something else like the ngrok domain doesn't help.

@jbdatascience
Copy link
Author

jbdatascience commented Apr 30, 2021

Welp, I tried, couldn't get anything to work. If I run heartrate on port 80 and then point ngrok to port 80 I get close, but I get a 404. Seems to have to do with the SERVER_NAME config but setting it to something else like the ngrok domain doesn't help.

When I run it on my local PC it seems to work fine, except in my webbrowser I do not see all of the expected output.
Especially I am missing the realtime movements of the horizontal bars on teh left.
I tried this in Edge, Chrome, Firefox (I could try MS IE of course but I did not do that yet)
So what could be cause of this?

I only see this:

image

@alexmojaki
Copy link
Owner

Try outside of IPython in just a regular script.

@jbdatascience
Copy link
Author

Try outside of IPython in just a regular script.

I will try that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants