import gradio as gr
import requests
import time
import socket
def check_url_status():
"""检查目标URL的状态"""
target_url = "http://47.95.6.204:51000/"
# 首先检查端口是否开放
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex(('47.95.6.204', 51000))
sock.close()
if result != 0:
return f"❌ 端口连接失败: 无法连接到 47.95.6.204:51000 (端口可能未开放)"
except Exception as e:
return f"❌ 网络错误: {str(e)}"
# 然后尝试HTTP请求
try:
response = requests.get(target_url, timeout=10)
return f"✅ URL状态: {response.status_code} - 可访问"
except requests.exceptions.ConnectTimeout:
return f"❌ 连接超时: 服务器响应时间过长"
except requests.exceptions.ConnectionError:
return f"❌ 连接错误: 无法连接到服务器"
except Exception as e:
return f"❌ URL错误: {str(e)}"
def ping_server():
"""简单的服务器连通性测试"""
try:
import subprocess
result = subprocess.run(['ping', '-n', '2', '47.95.6.204'],
capture_output=True, text=True, timeout=10)
if result.returncode == 0:
return "✅ 服务器IP可达"
else:
return "❌ 服务器IP不可达"
except Exception as e:
return f"❌ Ping测试失败: {str(e)}"
def create_webpage_display():
"""创建显示指定网页的HTML内容"""
# 添加详细的调试信息
debug_info = f"调试时间: {time.strftime('%Y-%m-%d %H:%M:%S')}
"
debug_info += f"目标URL: http://47.95.6.204:51000/
"
debug_info += f"网络连通性: {ping_server()}
"
debug_info += f"服务状态: {check_url_status()}
"
iframe_html = f'''
如果服务器不可达,可以尝试以下方案:
原始URL iframe:
演示URL iframe (应该可以正常显示):
在Hugging Face Spaces上部署时需要注意:
{content[:3000]}{'...' if len(content) > 3000 else ''}
{str(e)}
建议:
这是一个演示,说明iframe功能正常工作。
部署到Hugging Face时注意: