-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1ae586f
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Colab SSH Setup | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Google Colab SSH | ||
run: bash ./scripts/colab_ssh_setup.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Your Name | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Colab SSH Setup | ||
|
||
This repository provides a script and example to set up an SSH connection to Google Colab, allowing you to use Colab's resources locally in VS Code for resource-intensive tasks like machine learning. | ||
|
||
## Setup Instructions | ||
|
||
1. Clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/yourusername/colab-ssh-setup.git | ||
cd colab-ssh-setup | ||
Open scripts/colab_ssh_setup.sh and replace 'YOUR_NGROK_TOKEN' and 'YOUR_CHOSEN_PASSWORD' with your Ngrok token and desired SSH password. | ||
|
||
Run the script in a Google Colab notebook: | ||
``` | ||
!bash ./scripts/colab_ssh_setup.sh | ||
``` | ||
Follow the instructions in the Colab output to establish an SSH connection. | ||
Running the Flask App | ||
Navigate to the examples/flask_app directory: | ||
``` | ||
cd examples/flask_app | ||
``` | ||
Install the required packages: | ||
``` | ||
pip install -r ../../requirements.txt | ||
``` | ||
Run the Flask app: | ||
``` | ||
python app.py | ||
``` | ||
Access the app by opening a browser and going to http://localhost:5000. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from flask import Flask, render_template, request | ||
import pandas as pd | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def home(): | ||
return render_template('index.html') | ||
|
||
@app.route('/analyze', methods=['POST']) | ||
def analyze(): | ||
# Load Titanic dataset | ||
df = pd.read_csv('https://web.stanford.edu/class/archive/cs/cs109/cs109.1166/stuff/titanic.csv') | ||
|
||
# Example analysis: survival rate by class | ||
analysis = df.groupby('Pclass')['Survived'].mean().to_dict() | ||
|
||
return render_template('index.html', analysis=analysis) | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>Titanic Data Analysis</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1 class="mt-5">Titanic Data Analysis</h1> | ||
<form method="post" action="/analyze"> | ||
<button type="submit" class="btn btn-primary">Analyze</button> | ||
</form> | ||
{% if analysis %} | ||
<h2 class="mt-5">Analysis Results:</h2> | ||
<ul> | ||
{% for key, value in analysis.items() %} | ||
<li>Class {{ key }}: {{ value }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# Prevent disconnection by periodically clicking the "connect" button | ||
echo "function ClickConnect(){ | ||
console.log('Working'); | ||
document.querySelector('colab-toolbar-button#connect').click() | ||
} | ||
setInterval(ClickConnect, 60000)" > keepalive.js | ||
|
||
# Install Node.js to run the keepalive script | ||
apt-get update | ||
apt-get install -y nodejs | ||
|
||
# Load the keepalive.js script in the background using Node.js | ||
nohup node keepalive.js & | ||
|
||
# Install required Python packages | ||
pip install colab_ssh --upgrade | ||
pip install fastprogress | ||
|
||
# Setup SSH using colab_ssh | ||
python - << 'END_PYTHON' | ||
from colab_ssh import launch_ssh | ||
launch_ssh('YOUR_NGROK_TOKEN', password='YOUR_CHOSEN_PASSWORD') | ||
END_PYTHON | ||
|
||
echo "SSH setup complete. Please check the output above for connection details." |