ACCC1380 commited on
Commit
ee1c433
·
verified ·
1 Parent(s): 1fca959

Upload tunnel_1.ipynb

Browse files
Files changed (1) hide show
  1. tunnel_1.ipynb +57 -0
tunnel_1.ipynb ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "bea26831-aace-41ec-b150-ce950c88490a",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "http://r435.modal.host:34797\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import modal\n",
19
+ "import os\n",
20
+ "import time\n",
21
+ "local_port = 7860\n",
22
+ "with modal.forward(local_port, unencrypted=True) as tunnel:\n",
23
+ " hostname, remote_port = tunnel.tcp_socket\n",
24
+ " url = f\"http://{hostname}:{remote_port}\"\n",
25
+ " print(url)\n",
26
+ " \n",
27
+ " # 保持连接\n",
28
+ " try:\n",
29
+ " while True:\n",
30
+ " time.sleep(1)\n",
31
+ " except KeyboardInterrupt:\n",
32
+ " pass"
33
+ ]
34
+ }
35
+ ],
36
+ "metadata": {
37
+ "kernelspec": {
38
+ "display_name": "Python 3 (ipykernel)",
39
+ "language": "python",
40
+ "name": "python3"
41
+ },
42
+ "language_info": {
43
+ "codemirror_mode": {
44
+ "name": "ipython",
45
+ "version": 3
46
+ },
47
+ "file_extension": ".py",
48
+ "mimetype": "text/x-python",
49
+ "name": "python",
50
+ "nbconvert_exporter": "python",
51
+ "pygments_lexer": "ipython3",
52
+ "version": "3.11.2"
53
+ }
54
+ },
55
+ "nbformat": 4,
56
+ "nbformat_minor": 5
57
+ }