wli1995 commited on
Commit
9f8a5b5
·
verified ·
1 Parent(s): 481945d

Update gradio demo

Browse files
Files changed (2) hide show
  1. README.md +8 -3
  2. 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
- * Running on local URL: http://0.0.0.0:7860
72
- * To create a public link, set `share=True` in `launch()`.
 
 
 
 
73
  ```
74
- Then use the M.2 Accelerator card IP instead of the 0.0.0.0, and use chrome open the URL: http://[your ip]:7860
75
 
76
  ![gradio demo](./assert/gradio_demo.JPG)
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
  ![gradio demo](./assert/gradio_demo.JPG)
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(), css=custom_css)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ )