【书生大模型实战营】入门岛 第1关 Linux基础知识
完成SSH连接与端口映射并运行hello_world.py
1.创建个人开发机
登录InternStudio
输入收到的邮件中的邀请码就可以创建个人开发机了。
2.本地生成SSH Key
ssh-keygen
可以使用cat
来查看生成的公钥
3.在InternStudio配置公钥
在这里可以配置SSH Key
将本地生成的公钥输入到指定位置
4.使用本地机器SSH连接开发机
这里使用VSCode Remote-SSH 插件连接开发机
复制开发机SSH连接中的内容进行连接
连接成功
5. 端口映射
创建hello_world.py并在开发机上运行
import socket
import re
import gradio as gr
# 获取主机名
def get_hostname():
hostname = socket.gethostname()
match = re.search(r'-(\d+)$', hostname)
name = match.group(1)
return name
# 创建 Gradio 界面
with gr.Blocks(gr.themes.Soft()) as demo:
html_code = f"""
<p align="center">
<a href="https://intern-ai.org.cn/home">
<img src="https://intern-ai.org.cn/assets/headerLogo-4ea34f23.svg" alt="Logo" width="20%" style="border-radius: 5px;">
</a>
</p>
<h1 style="text-align: center;">☁️ Welcome {get_hostname()} user, welcome to the ShuSheng LLM Practical Camp Course!</h1>
<h2 style="text-align: center;">😀 Let’s go on a journey through ShuSheng Island together.</h2>
<p align="center">
<a href="https://github.com/InternLM/Tutorial/blob/camp3">
<img src="https://oss.lingkongstudy.com.cn/blog/202406301604074.jpg" alt="Logo" width="20%" style="border-radius: 5px;">
</a>
</p>
"""
gr.Markdown(html_code)
demo.launch()
此时,本地还不能够访问,需要进行端口映射,找到我们的开发机,点击自定义服务,复制第一条命令,在本地的终端执行。
这样就可以在本地访问了,VSCode提供了自动端口映射的功能,我们不需要手动配置,我们可以使用Ctrl+Shift+~
快捷键唤醒终端,在终端的右侧可以找到端口选项。