Update gradio demo
Browse files- README.md +8 -3
- python/gradio_demo.py +35 -2
README.md
CHANGED
|
@@ -58,6 +58,7 @@ Input Data:
|
|
| 58 |
|
| 59 |
#### Inference with M.2 Accelerator card
|
| 60 |
```
|
|
|
|
| 61 |
$python3 gradio_demo.py
|
| 62 |
[INFO] Available providers: ['AXCLRTExecutionProvider']
|
| 63 |
[INFO] Using provider: AXCLRTExecutionProvider
|
|
@@ -68,10 +69,14 @@ $python3 gradio_demo.py
|
|
| 68 |
[INFO] SOC Name: AX650N
|
| 69 |
[INFO] VNPU type: VNPUType.DISABLED
|
| 70 |
[INFO] Compiler version: 5.0-patch1 2295293f
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
```
|
| 74 |
-
Then
|
| 75 |
|
| 76 |

|
| 77 |
|
|
|
|
| 58 |
|
| 59 |
#### Inference with M.2 Accelerator card
|
| 60 |
```
|
| 61 |
+
$cd python
|
| 62 |
$python3 gradio_demo.py
|
| 63 |
[INFO] Available providers: ['AXCLRTExecutionProvider']
|
| 64 |
[INFO] Using provider: AXCLRTExecutionProvider
|
|
|
|
| 69 |
[INFO] SOC Name: AX650N
|
| 70 |
[INFO] VNPU type: VNPUType.DISABLED
|
| 71 |
[INFO] Compiler version: 5.0-patch1 2295293f
|
| 72 |
+
|
| 73 |
+
==================================================
|
| 74 |
+
🌐 AI图片上色 Web UI 已启动!
|
| 75 |
+
🔗 本地访问: http://127.0.0.1:7860
|
| 76 |
+
🔗 局域网访问: http://10.126.33.124:7860
|
| 77 |
+
==================================================
|
| 78 |
```
|
| 79 |
+
Then open the link in the browser to use the web UI:
|
| 80 |
|
| 81 |

|
| 82 |
|
python/gradio_demo.py
CHANGED
|
@@ -5,6 +5,7 @@ from PIL import Image, ImageEnhance
|
|
| 5 |
import numpy as np
|
| 6 |
import axengine as axe
|
| 7 |
import cv2
|
|
|
|
| 8 |
|
| 9 |
# ==============================
|
| 10 |
# 模拟上色函数(请替换为你的实际模型)
|
|
@@ -172,7 +173,39 @@ with gr.Blocks(title="AI 图片上色工具") as demo:
|
|
| 172 |
inputs=[input_image, model_choice],
|
| 173 |
outputs=[output_image, download_btn]
|
| 174 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
-
# 启动
|
| 177 |
if __name__ == "__main__":
|
| 178 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, theme=gr.themes.Soft()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import axengine as axe
|
| 7 |
import cv2
|
| 8 |
+
import socket
|
| 9 |
|
| 10 |
# ==============================
|
| 11 |
# 模拟上色函数(请替换为你的实际模型)
|
|
|
|
| 173 |
inputs=[input_image, model_choice],
|
| 174 |
outputs=[output_image, download_btn]
|
| 175 |
)
|
| 176 |
+
def get_local_ip():
|
| 177 |
+
"""获取本机局域网IP地址"""
|
| 178 |
+
try:
|
| 179 |
+
# 创建一个UDP连接(不会真正发送数据)
|
| 180 |
+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
| 181 |
+
s.connect(("8.8.8.8", 80)) # 连接到公共DNS(Google)
|
| 182 |
+
ip = s.getsockname()[0]
|
| 183 |
+
return ip
|
| 184 |
+
except Exception:
|
| 185 |
+
# 回退到 localhost
|
| 186 |
+
return "127.0.0.1"
|
| 187 |
+
|
| 188 |
|
|
|
|
| 189 |
if __name__ == "__main__":
|
| 190 |
+
# demo.launch(server_name="0.0.0.0", server_port=7860, theme=gr.themes.Soft())
|
| 191 |
+
|
| 192 |
+
server_port = 7860
|
| 193 |
+
server_name = "0.0.0.0"
|
| 194 |
+
|
| 195 |
+
# 获取本机IP
|
| 196 |
+
local_ip = get_local_ip()
|
| 197 |
+
|
| 198 |
+
# 打印可点击的URL(大多数终端支持点击)
|
| 199 |
+
print("\n" + "="*50)
|
| 200 |
+
print("🌐 AI图片上色 Web UI 已启动!")
|
| 201 |
+
print(f"🔗 本地访问: http://127.0.0.1:{server_port}")
|
| 202 |
+
if local_ip != "127.0.0.1":
|
| 203 |
+
print(f"🔗 局域网访问: http://{local_ip}:{server_port}")
|
| 204 |
+
print("="*50 + "\n")
|
| 205 |
+
|
| 206 |
+
# 启动Gradio应用
|
| 207 |
+
demo.launch(
|
| 208 |
+
server_name=server_name,
|
| 209 |
+
server_port=server_port,
|
| 210 |
+
theme=gr.themes.Soft()
|
| 211 |
+
)
|