


<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>高级响应式网页设计</title><script src="https://cdn.tailwindcss.com"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet"><style>/* 自定义滚动条样式 */::-webkit-scrollbar {width: 8px;}::-webkit-scrollbar-track {background: #f5f5f5;}::-webkit-scrollbar-thumb {background: #888;border-radius: 4px;}</style></head><body class="font-sans antialiased text-gray-900 leading-normal tracking-wider bg-gray-50"><!-- 导航栏 --><nav class="fixed w-full bg-white shadow-md z-10"><div class="container mx-auto flex flex-wrap items-center justify-between p-4"><div class="flex items-center flex-shrink-0 text-white mr-6"><span class="font-semibold text-xl tracking-tight">Advanced Design</span></div><div class="block lg:hidden"><button id="menu-toggle" class="flex items-center px-3 py-2 border rounded text-teal-200 border-teal-400 hover:text-white hover:border-white"><svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg></button></div><div class="w-full block flex-grow lg:flex lg:items-center lg:w-auto hidden" id="menu"><ul class="list-reset lg:flex justify-end flex-1 items-center"><li class="mr-3"><a href="#hero" class="inline-block py-2 px-3 text-teal-800 no-underline hover:text-teal-600 hover:border-b-2 border-teal-600">首页</a></li><li class="mr-3"><a href="#features" class="inline-block py-2 px-3 text-teal-800 no-underline hover:text-teal-600 hover:border-b-2 border-teal-600">特色</a></li><li class="mr-3"><a href="#portfolio" class="inline-block py-2 px-3 text-teal-800 no-underline hover:text-teal-600 hover:border-b-2 border-teal-600">案例</a></li><li class="mr-3"><a href="#subscribe" class="inline-block py-2 px-3 text-teal-800 no-underline hover:text-teal-600 hover:border-b-2 border-teal-600">订阅</a></li><li><a href="#contact" class="inline-block py-2 px-3 bg-teal-800 text-white hover:bg-teal-700 rounded-full">联系我们</a></li></ul></div></div></nav><!-- 英雄区域 --><section id="hero" class="h-screen bg-cover bg-center" style="background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('https://picsum.photos/1920/1080')"><div class="container mx-auto h-full flex flex-col justify-center items-center text-center text-white"><h1 class="text-5xl lg:text-6xl font-bold mb-4">创新设计驱动未来</h1><p class="text-xl lg:text-2xl mb-8">我们致力于打造卓越的用户体验,结合前沿技术与美学设计</p><div class="flex flex-col lg:flex-row space-y-4 lg:space-y-0 lg:space-x-4"><a href="#contact" class="px-8 py-3 bg-white text-teal-800 font-bold rounded-full hover:bg-teal-50 transition-shadow shadow-md hover:shadow-lg">立即咨询</a><a href="#features" class="px-8 py-3 border-2 border-white text-white font-bold rounded-full hover:bg-white hover:text-teal-800 transition-colors">了解更多</a></div></div></section><!-- 特色功能区 --><section id="features" class="py-20 bg-gray-50"><div class="container mx-auto px-4"><h2 class="text-4xl font-bold text-center mb-12">核心优势</h2><div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"><div class="bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow p-6"><div class="w-16 h-16 bg-teal-100 rounded-full flex items-center justify-center mb-4"><i class="fas fa-layer-group text-2xl text-teal-800"></i></div><h3 class="text-xl font-bold mb-2">创意设计</h3><p class="text-gray-700">独特的视觉语言,让每个项目都与众不同</p></div><div class="bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow p-6"><div class="w-16 h-16 bg-teal-100 rounded-full flex items-center justify-center mb-4"><i class="fas fa-code text-2xl text-teal-800"></i></div><h3 class="text-xl font-bold mb-2">技术实现</h3><p class="text-gray-700">前沿技术栈支撑,确保高性能与稳定性</p></div><div class="bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow p-6"><div class="w-16 h-16 bg-teal-100 rounded-full flex items-center justify-center mb-4"><i class="fas fa-headset text-2xl text-teal-800"></i></div><h3 class="text-xl font-bold mb-2">优质服务</h3><p class="text-gray-700">7×24小时服务,全程保障项目落地</p></div></div></div></section><!-- 案例展示区 --><section id="portfolio" class="py-20"><div class="container mx-auto px-4"><h2 class="text-4xl font-bold text-center mb-12">成功案例</h2><div class="swiper portfolio-slider"><div class="swiper-wrapper"><div class="swiper-slide"><img src="https://picsum.photos/1200/800" alt="案例1" class="w-full h-64 object-cover rounded-lg shadow-md"><h3 class="text-xl font-bold mt-4">企业官网设计</h3><p class="text-gray-700">通过响应式设计提升品牌形象</p></div><div class="swiper-slide"><img src="https://picsum.photos/1200/800" alt="案例2" class="w-full h-64 object-cover rounded-lg shadow-md"><h3 class="text-xl font-bold mt-4">电商平台开发</h3><p class="text-gray-700">优化用户体验提升转化率</p></div><div class="swiper-slide"><img src="https://picsum.photos/1200/800" alt="案例3" class="w-full h-64 object-cover rounded-lg shadow-md"><h3 class="text-xl font-bold mt-4">移动应用界面</h3><p class="text-gray-700">简洁交互设计增强用户粘性</p></div></div><div class="swiper-pagination"></div></div></div></section><!-- 订阅区 --><section id="subscribe" class="py-20 bg-teal-800 text-white text-center"><div class="container mx-auto px-4"><h2 class="text-4xl font-bold mb-8">订阅我们的资讯</h2><p class="text-xl mb-12">获取最新行业动态与优惠活动</p><form class="flex flex-col md:flex-row justify-center space-y-4 md:space-y-0 md:space-x-4"><input type="email" placeholder="输入你的邮箱" class="px-6 py-3 rounded-full w-full md:w-1/2 focus:outline-none focus:shadow-outline"><button type="submit" class="px-8 py-3 bg-white text-teal-800 font-bold rounded-full hover:shadow-lg transition-shadow">立即订阅</button></form></div></section><!-- 页脚 --><footer id="contact" class="bg-gray-900 text-white py-12"><div class="container mx-auto px-4"><div class="flex flex-col md:flex-row justify-between items-center"><div class="mb-6 md:mb-0"><a href="#" class="text-xl font-bold text-teal-300 inline-block mb-4">Advanced Design</a><p class="text-gray-400">地址:上海市浦东新区世纪大道100号</p><p class="text-gray-400">电话:+86 10-12345678</p><p class="text-gray-400">邮箱:info@advdesign.com</p></div><div class="flex space-x-4"><a href="#" class="text-teal-300 hover:text-teal-200"><i class="fab fa-facebook-f"></i></a><a href="#" class="text-teal-300 hover:text-teal-200"><i class="fab fa-twitter"></i></a><a href="#" class="text-teal-300 hover:text-teal-200"><i class="fab fa-instagram"></i></a><a href="#" class="text-teal-300 hover:text-teal-200"><i class="fab fa-linkedin-in"></i></a></div></div><p class="text-center mt-8 text-gray-400">© 2025 Advanced Design. 保留所有权利</p></div></footer><!-- Swiper JS --><script src="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.js"></script><script>// 导航菜单切换document.getElementById('menu-toggle').addEventListener('click', function() {const menu = document.getElementById('menu');menu.classList.toggle('hidden');});// 案例轮播new Swiper('.portfolio-slider', {pagination: {el: '.swiper-pagination',clickable: true,},breakpoints: {640: {slidesPerView: 1,spaceBetween: 30,},1024: {slidesPerView: 2,spaceBetween: 40,},1440: {slidesPerView: 3,spaceBetween: 50,}}});</script></body></html>
# --------------------------------------------------------
# Based on yolov10
# https://github.com/THU-MIG/yolov10/app.py
# --------------------------------------------------------'# flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whlimport gradio as gr
import cv2
import tempfile
from ultralytics import YOLOdef yolov12_inference(image, video, model_id, image_size, conf_threshold):model = YOLO(model_id)if image:results = model.predict(source=image, imgsz=image_size, conf=conf_threshold)annotated_image = results[0].plot()return annotated_image[:, :, ::-1], Noneelse:video_path = tempfile.mktemp(suffix=".webm")with open(video_path, "wb") as f:with open(video, "rb") as g:f.write(g.read())cap = cv2.VideoCapture(video_path)fps = cap.get(cv2.CAP_PROP_FPS)frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))output_video_path = tempfile.mktemp(suffix=".webm")out = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*'vp80'), fps, (frame_width, frame_height))while cap.isOpened():ret, frame = cap.read()if not ret:breakresults = model.predict(source=frame, imgsz=image_size, conf=conf_threshold)annotated_frame = results[0].plot()out.write(annotated_frame)cap.release()out.release()return None, output_video_pathdef yolov12_inference_for_examples(image, model_path, image_size, conf_threshold):annotated_image, _ = yolov12_inference(image, None, model_path, image_size, conf_threshold)return annotated_imagedef app():with gr.Blocks():with gr.Row():with gr.Column():image = gr.Image(type="pil", label="Image", visible=True)video = gr.Video(label="Video", visible=False)input_type = gr.Radio(choices=["Image", "Video"],value="Image",label="Input Type",)model_id = gr.Dropdown(label="Model",choices=["yolov12n.pt","yolov12s.pt","yolov12m.pt","yolov12l.pt","yolov12x.pt",],value="yolov12m.pt",)image_size = gr.Slider(label="Image Size",minimum=320,maximum=1280,step=32,value=640,)conf_threshold = gr.Slider(label="Confidence Threshold",minimum=0.0,maximum=1.0,step=0.05,value=0.25,)yolov12_infer = gr.Button(value="Detect Objects")with gr.Column():output_image = gr.Image(type="numpy", label="Annotated Image", visible=True)output_video = gr.Video(label="Annotated Video", visible=False)def update_visibility(input_type):image = gr.update(visible=True) if input_type == "Image" else gr.update(visible=False)video = gr.update(visible=False) if input_type == "Image" else gr.update(visible=True)output_image = gr.update(visible=True) if input_type == "Image" else gr.update(visible=False)output_video = gr.update(visible=False) if input_type == "Image" else gr.update(visible=True)return image, video, output_image, output_videoinput_type.change(fn=update_visibility,inputs=[input_type],outputs=[image, video, output_image, output_video],)def run_inference(image, video, model_id, image_size, conf_threshold, input_type):if input_type == "Image":return yolov12_inference(image, None, model_id, image_size, conf_threshold)else:return yolov12_inference(None, video, model_id, image_size, conf_threshold)yolov12_infer.click(fn=run_inference,inputs=[image, video, model_id, image_size, conf_threshold, input_type],outputs=[output_image, output_video],)gr.Examples(examples=[["ultralytics/assets/bus.jpg","yolov12s.pt",640,0.25,],["ultralytics/assets/zidane.jpg","yolov12x.pt",640,0.25,],],fn=yolov12_inference_for_examples,inputs=[image,model_id,image_size,conf_threshold,],outputs=[output_image],cache_examples='lazy',)gradio_app = gr.Blocks()
with gradio_app:gr.HTML("""<h1 style='text-align: center'>YOLOv12: Attention-Centric Real-Time Object Detectors</h1>""")gr.HTML("""<h3 style='text-align: center'><a href='https://arxiv.org/abs/2502.12524' target='_blank'>arXiv</a> | <a href='https://github.com/sunsmarterjie/yolov12' target='_blank'>github</a></h3>""")with gr.Row():with gr.Column():app()
if __name__ == '__main__':gradio_app.launch()
import gradio as gr
import cv2
import numpy as np
from ultralytics import YOLO# 全局变量
model = None
current_config = {}
running = False
target_classes = None
class_names = {} # 存储类别名称映射# 中文到英文类别映射
chinese_class_mapping = {"人": "person","人类": "person","电脑": "laptop","笔记本": "laptop","汽车": "car","车辆": "car","狗": "dog","猫": "cat","手机": "cell phone","杯子": "cup","瓶子": "bottle","椅子": "chair","桌子": "dining table","电视": "tv","飞机": "airplane","自行车": "bicycle","船": "boat","公交车": "bus","火车": "train","摩托车": "motorcycle","鸟": "bird","羊": "sheep","牛": "cow","大象": "elephant","熊": "bear","斑马": "zebra","长颈鹿": "giraffe","背包": "backpack","雨伞": "umbrella","手提包": "handbag","领带": "tie","行李箱": "suitcase","飞盘": "frisbee","滑雪板": "skis","雪板": "snowboard","运动球": "sports ball","风筝": "kite","棒球棒": "baseball bat","棒球手套": "baseball glove","滑板": "skateboard","冲浪板": "surfboard","网球拍": "tennis racket","酒瓶": "wine glass","杯子": "cup","叉子": "fork","刀": "knife","勺子": "spoon","碗": "bowl","香蕉": "banana","苹果": "apple","三明治": "sandwich","橙子": "orange","西兰花": "broccoli","胡萝卜": "carrot","热狗": "hot dog","披萨": "pizza","甜甜圈": "donut","蛋糕": "cake","沙发": "couch","盆栽": "potted plant","床": "bed","餐桌": "dining table","马桶": "toilet","显示器": "monitor","鼠标": "mouse","键盘": "keyboard","遥控器": "remote","微波炉": "microwave","烤箱": "oven","烤面包机": "toaster","水槽": "sink","冰箱": "refrigerator","书": "book","时钟": "clock","花瓶": "vase","剪刀": "scissors","泰迪熊": "teddy bear","吹风机": "hair drier","牙刷": "toothbrush"
}def initialize_model(model_id, image_size, conf_threshold):global model, current_config, class_namesif model is None or current_config != (model_id, image_size, conf_threshold):model = YOLO(model_id)current_config = (model_id, image_size, conf_threshold)# 获取模型的类别名称映射class_names = model.namesdef process_frame(frame):global model, target_classesif model is None:return frame# 如果有指定类别,则只检测这些类别classes_to_detect = Noneif target_classes:classes_to_detect = [class_id for class_id, name in class_names.items()if name.lower() in [t.lower().strip() for t in target_classes]]results = model.predict(source=frame,imgsz=current_config[1],conf=current_config[2],classes=classes_to_detect)annotated_frame = results[0].plot()return annotated_frame[:, :, ::-1]def camera_stream():cap = cv2.VideoCapture(0)while running:ret, frame = cap.read()if not ret:breakframe = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)yield framecap.release()def detect_frames():for frame in camera_stream():processed = process_frame(frame)yield cv2.cvtColor(processed, cv2.COLOR_RGB2BGR)def toggle_detection(start_btn):global runningrunning = not runningreturn "停止检测" if running else "开始检测"def update_target_classes(class_input):global target_classes, chinese_class_mappingif class_input:# 处理中文输入input_classes = [c.strip() for c in class_input.split(",")]target_classes = []for cls in input_classes:if cls in chinese_class_mapping:target_classes.append(chinese_class_mapping[cls])else:# 如果不是中文,直接使用输入target_classes.append(cls)return f"检测目标已设置为: {', '.join(input_classes)} ({', '.join(target_classes)})"else:target_classes = Nonereturn "将检测所有类别"def app():# 使用Soft主题并设置最大宽度with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 1200px !important}") as demo:# 自定义CSS样式css = """.title {text-align: center;font-size: 2.5em;font-weight: bold;color: #2b5876;margin-bottom: 20px;background: linear-gradient(135deg, #2b5876 0%, #4e4376 100%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;}.panel {background: white;border-radius: 10px;padding: 20px;box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);margin-bottom: 20px;}.button-primary {background: linear-gradient(135deg, #2b5876 0%, #4e4376 100%) !important;color: white !important;border: none !important;font-weight: bold !important;}.button-primary:hover {box-shadow: 0 4px 8px rgba(43, 88, 118, 0.3) !important;}.output-container {border-radius: 10px;overflow: hidden;box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);margin-top: -50px; /* 将检测框上移 */}.status-box {background: #f8f9fa;border-radius: 8px;padding: 15px;margin-top: 10px;}.class-input {margin-bottom: 15px;}.example-list {font-size: 0.9em;color: #666;margin-top: 10px;}"""# 应用CSSgr.HTML(f"<style>{css}</style>")# 标题区域with gr.Column(elem_classes=["panel"]):gr.HTML('<div class="title">YOLOv12 智能目标检测系统</div>')gr.Markdown("""**使用说明**: 1. 选择模型和设置参数 2. 输入要检测的目标类别(中英文均可,如: 人, car, 电脑) 3. 点击"开始检测"按钮 4. 多个类别用逗号分隔(如: 人, 汽车, dog) """)with gr.Row():# 控制面板with gr.Column(scale=1, elem_classes=["panel"]):model_selector = gr.Dropdown(label="🛠️ 选择检测模型",choices=["yolov12n.pt","yolov12s.pt","yolov12m.pt","yolov12l.pt","yolov12x.pt",],value="yolov12m.pt")with gr.Accordion("⚙️ 高级设置", open=False):image_size = gr.Slider(label="📏 推理尺寸",minimum=320,maximum=1280,step=32,value=640,info="较大的尺寸提高精度但降低速度")conf_threshold = gr.Slider(label="🎯 置信度阈值",minimum=0.0,maximum=1.0,step=0.05,value=0.4,info="值越高检测结果越可靠但可能漏检")with gr.Column(elem_classes=["class-input"]):class_input = gr.Textbox(label="🎯 检测目标 (中英文)",placeholder="输入要检测的类别,如: 人, car, 电脑",info="多个类别用逗号分隔,留空则检测所有类别")gr.Markdown("""<div class="example-list"><b>常用类别示例</b>:<br>人, 汽车, 狗, 猫, 手机, 电脑, 椅子, 桌子, 电视, 飞机, 自行车</div>""")class_status = gr.Textbox(label="🔄 状态",interactive=False,elem_classes=["status-box"])start_btn = gr.Button("▶️ 开始检测",variant="primary",elem_classes=["button-primary"])# 输出区域with gr.Column(scale=2, elem_classes=["output-container"]):output_video = gr.Image(label="🔍 实时检测结果",height=500)gr.Markdown("""**检测统计**: - 支持80种常见目标检测 - 实时处理速度: 30-60 FPS (取决于模型和硬件) - 最佳实践: 使用yolov12s平衡速度和精度 """)# 事件处理class_input.change(fn=update_target_classes,inputs=class_input,outputs=class_status)start_btn.click(fn=toggle_detection,inputs=[start_btn],outputs=[start_btn],queue=False).then(fn=lambda: gr.Image(interactive=True),outputs=output_video).then(fn=initialize_model,inputs=[model_selector, image_size, conf_threshold],queue=False).then(fn=detect_frames,outputs=output_video)return demoif __name__ == "__main__":# 忽略FlashAttention警告import warningswarnings.filterwarnings("ignore", message="FlashAttention is not available")gradio_app = app()gradio_app.queue().launch(server_name="0.0.0.0",server_port=7861,share=True,inbrowser=True,)# "172.17.173.38"
import gradio as gr
import cv2
import numpy as np
from ultralytics import YOLO
import speech_recognition as sr# 全局变量
model = None
current_config = {}
running = False # 控制检测状态的标志
target_class = None # 控制目标类别,初始为空def initialize_model(model_id, image_size, conf_threshold):global model, current_configif model is None or current_config != (model_id, image_size, conf_threshold):model = YOLO(model_id)current_config = (model_id, image_size, conf_threshold)def process_frame(frame):global model, target_classif model is None:return frame# 如果target_class已设置,使用该类别过滤目标results = model.predict(source=frame, imgsz=current_config[1], conf=current_config[2])# 根据目标类别进行筛选if target_class is not None:results = [result[result.names.index(target_class)] for result in results if target_class in result.names]annotated_frame = results[0].plot()return annotated_frame[:, :, ::-1]def camera_stream():cap = cv2.VideoCapture(0)while running:ret, frame = cap.read()if not ret:breakframe = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)yield framecap.release()def detect_frames():for frame in camera_stream():processed = process_frame(frame)yield cv2.cvtColor(processed, cv2.COLOR_RGB2BGR)def toggle_detection(start_btn):global runningrunning = not runningreturn "停止检测" if running else "开始检测"def recognize_speech():# 使用语音识别库来获取用户的指令recognizer = sr.Recognizer()with sr.Microphone() as source:print("请说话...")audio = recognizer.listen(source)try:command = recognizer.recognize_google(audio, language="zh-CN")print("你说的是: " + command)return commandexcept sr.UnknownValueError:return "无法识别语音"except sr.RequestError:return "语音识别服务不可用"def set_target_class(command):global target_classif "人" in command: # 例如,用户说“只识别人”target_class = "person"else:target_class = None # 默认识别所有目标def app():with gr.Blocks() as demo:gr.HTML("""<h1 style='text-align: center'>YOLOv12 实时摄像头检测</h1>""")with gr.Row():with gr.Column():model_selector = gr.Dropdown(label="选择模型",choices=["yolov12n.pt","yolov12s.pt","yolov12m.pt","yolov12l.pt","yolov12x.pt",],value="yolov12m.pt")with gr.Accordion("高级设置", open=False):image_size = gr.Slider(label="推理尺寸",minimum=320,maximum=1280,step=32,value=640)conf_threshold = gr.Slider(label="置信度阈值",minimum=0.0,maximum=1.0,step=0.05,value=0.25)start_btn = gr.Button("开始检测", variant="primary")with gr.Column():output_video = gr.Image(label="检测结果")# 事件处理start_btn.click(fn=toggle_detection,inputs=[start_btn],outputs=[start_btn],queue=False).then(fn=lambda: gr.Image(interactive=True),outputs=output_video).then(fn=initialize_model,inputs=[model_selector, image_size, conf_threshold],queue=False).then(fn=detect_frames,outputs=output_video)# 语音识别处理gr.Button("说话控制", variant="secondary").click(fn=recognize_speech,outputs=None).then(fn=set_target_class,inputs=[recognize_speech],queue=False)return demoif __name__ == "__main__":gradio_app = app()gradio_app.queue().launch()