Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,16 @@ app = FastAPI()
|
|
13 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
14 |
model = YOLO('kunin-mice-pose.v0.1.0.pt')
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
@spaces.GPU
|
17 |
def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8):
|
18 |
"""
|
@@ -115,36 +125,47 @@ def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8)
|
|
115 |
|
116 |
return output_path, report
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
### 使用说明
|
149 |
1. 上传视频文件
|
150 |
2. 设置处理参数:
|
@@ -160,8 +181,12 @@ demo = gr.Interface(
|
|
160 |
- 处理时间与视频长度和分辨率相关
|
161 |
- 置信度建议范围:0.2-0.5
|
162 |
- 最大检测数量建议根据实际场景设置
|
163 |
-
"""
|
164 |
-
)
|
165 |
|
166 |
if __name__ == "__main__":
|
167 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
13 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
14 |
model = YOLO('kunin-mice-pose.v0.1.0.pt')
|
15 |
|
16 |
+
# 添加认证函数
|
17 |
+
def auth_user(username, password):
|
18 |
+
# 你可以添加多个用户
|
19 |
+
valid_credentials = {
|
20 |
+
"kunin": "123456",
|
21 |
+
"user1": "password1",
|
22 |
+
# 可以添加更多用户
|
23 |
+
}
|
24 |
+
return username in valid_credentials and valid_credentials[username] == password
|
25 |
+
|
26 |
@spaces.GPU
|
27 |
def process_video(video_path, process_seconds=20, conf_threshold=0.2, max_det=8):
|
28 |
"""
|
|
|
125 |
|
126 |
return output_path, report
|
127 |
|
128 |
+
# 创建 Gradio 界面
|
129 |
+
with gr.Blocks() as demo:
|
130 |
+
gr.Markdown("# 🐁 小鼠行为分析 (Mice Behavior Analysis)")
|
131 |
+
gr.Markdown("上传视频来检测和分析小鼠行为 | Upload a video to detect and analyze mice behavior")
|
132 |
+
|
133 |
+
with gr.Row():
|
134 |
+
with gr.Column():
|
135 |
+
video_input = gr.Video(label="输入视频")
|
136 |
+
process_seconds = gr.Number(
|
137 |
+
label="处理时长(秒,0表示处理整个视频)",
|
138 |
+
value=20
|
139 |
+
)
|
140 |
+
conf_threshold = gr.Slider(
|
141 |
+
minimum=0.1,
|
142 |
+
maximum=1.0,
|
143 |
+
value=0.2,
|
144 |
+
step=0.05,
|
145 |
+
label="置信度阈值",
|
146 |
+
info="越高越严格,建议范围0.2-0.5"
|
147 |
+
)
|
148 |
+
max_det = gr.Slider(
|
149 |
+
minimum=1,
|
150 |
+
maximum=10,
|
151 |
+
value=8,
|
152 |
+
step=1,
|
153 |
+
label="最大检测数量",
|
154 |
+
info="每帧最多检测的目标数量"
|
155 |
+
)
|
156 |
+
process_btn = gr.Button("开始处理")
|
157 |
+
|
158 |
+
with gr.Column():
|
159 |
+
video_output = gr.Video(label="检测结果")
|
160 |
+
report_output = gr.Textbox(label="分析报告")
|
161 |
+
|
162 |
+
process_btn.click(
|
163 |
+
fn=process_video,
|
164 |
+
inputs=[video_input, process_seconds, conf_threshold, max_det],
|
165 |
+
outputs=[video_output, report_output]
|
166 |
+
)
|
167 |
+
|
168 |
+
gr.Markdown("""
|
169 |
### 使用说明
|
170 |
1. 上传视频文件
|
171 |
2. 设置处理参数:
|
|
|
181 |
- 处理时间与视频长度和分辨率相关
|
182 |
- 置信度建议范围:0.2-0.5
|
183 |
- 最大检测数量建议根据实际场景设置
|
184 |
+
""")
|
|
|
185 |
|
186 |
if __name__ == "__main__":
|
187 |
+
demo.launch(
|
188 |
+
server_name="0.0.0.0",
|
189 |
+
server_port=7860,
|
190 |
+
auth=auth_user,
|
191 |
+
auth_message="请输入用户名和密码"
|
192 |
+
)
|