Dennis Huang commited on
Commit
3f3e057
·
1 Parent(s): ba0945a

Initial Push

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +180 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -8,7 +8,7 @@ sdk_version: 6.5.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- short_description: '111111111111111111111111111111111111111111111111111111111111'
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
+ short_description: 'Full-Duplex Omni-modal Live Streaming'
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Hugging Face Spaces 版本 - LiveKit 实时音视频对话
6
+ """
7
+
8
+ import gradio as gr
9
+ import os
10
+
11
+ def main():
12
+ # 获取 Hugging Face Space 的配置
13
+ space_id = os.getenv('SPACE_ID', 'unknown')
14
+
15
+ with gr.Blocks(
16
+ title="LiveKit 实时音视频对话",
17
+ css="""
18
+ /* 简单清理样式,避免滚动条 */
19
+ html, body {
20
+ margin: 0 !important;
21
+ padding: 0 !important;
22
+ overflow: hidden !important;
23
+ }
24
+
25
+ /* 隐藏 Gradio 默认内容区域 */
26
+ .gradio-container {
27
+ position: relative !important;
28
+ overflow: hidden !important;
29
+ }
30
+
31
+ /* iframe 使用固定定位填满整个视口 */
32
+ #fullscreen-iframe {
33
+ position: fixed !important;
34
+ top: 0 !important;
35
+ left: 0 !important;
36
+ right: 0 !important;
37
+ bottom: 0 !important;
38
+ width: 100vw !important;
39
+ height: 100vh !important;
40
+ border: none !important;
41
+ margin: 0 !important;
42
+ padding: 0 !important;
43
+ z-index: 9999 !important;
44
+ }
45
+ """,
46
+ head="""
47
+ <script>
48
+ // 动态调整 iframe 以适配 Hugging Face Spaces
49
+ document.addEventListener('DOMContentLoaded', function() {
50
+ document.documentElement.style.overflow = 'hidden';
51
+ document.body.style.overflow = 'hidden';
52
+
53
+ function adjustIframe() {
54
+ const iframe = document.querySelector('#fullscreen-iframe');
55
+ if (!iframe) return;
56
+
57
+ // 查找 Hugging Face 顶部导航栏
58
+ const hfHeader = document.querySelector('header');
59
+ const gradioContainer = document.querySelector('.gradio-container');
60
+
61
+ let topOffset = 0;
62
+
63
+ // 计算顶部偏移量
64
+ if (hfHeader) {
65
+ topOffset = hfHeader.offsetHeight;
66
+ console.log('🔍 检测到 HF 导航栏高度:', topOffset + 'px');
67
+ } else if (gradioContainer) {
68
+ const rect = gradioContainer.getBoundingClientRect();
69
+ topOffset = rect.top;
70
+ console.log('🔍 使用 Gradio 容器顶部偏移:', topOffset + 'px');
71
+ }
72
+
73
+ // 设置 iframe 位置和大小,避开顶部导航
74
+ iframe.style.top = topOffset + 'px';
75
+ iframe.style.height = 'calc(100vh - ' + topOffset + 'px)';
76
+
77
+ console.log('✅ iframe 已调整 - 顶部偏移:', topOffset + 'px', '高度: calc(100vh - ' + topOffset + 'px)');
78
+ }
79
+
80
+ // 多次尝试调整
81
+ setTimeout(adjustIframe, 50);
82
+ setTimeout(adjustIframe, 200);
83
+ setTimeout(adjustIframe, 500);
84
+ setTimeout(adjustIframe, 1000);
85
+ setTimeout(adjustIframe, 2000);
86
+
87
+ // 监听窗口大小变化
88
+ window.addEventListener('resize', adjustIframe);
89
+
90
+ console.log('✅ Hugging Face Spaces iframe 自适应已启动');
91
+ });
92
+
93
+ // 模式切换功能(通过键盘)
94
+ document.addEventListener('keydown', function(e) {
95
+ const iframe = document.querySelector('#fullscreen-iframe');
96
+ if (!iframe) return;
97
+
98
+ // 数字键 0 - 音频模式
99
+ if (e.key === '0') {
100
+ iframe.src = 'https://minicpm-omni.openbmb.cn/?type=0';
101
+ console.log('切换到音频模式');
102
+ }
103
+ // 数字键 1 - 视频模式
104
+ else if (e.key === '1') {
105
+ iframe.src = 'https://minicpm-omni.openbmb.cn/?type=1';
106
+ console.log('切换到视频模式');
107
+ }
108
+ // 数字键 1 - 测试模式
109
+ else if (e.key === '3') {
110
+ iframe.src = 'https://minicpm-omni.openbmb.cn/?type=3';
111
+ console.log('切换到视频模式');
112
+ }
113
+ // R 键 - 刷新
114
+ else if (e.key === 'r' || e.key === 'R') {
115
+ iframe.src = iframe.src;
116
+ console.log('刷新 iframe');
117
+ }
118
+ });
119
+ </script>
120
+ """
121
+ ) as demo:
122
+
123
+ # 全屏 iframe,使用 fixed 定位填满可用空间
124
+ gr.HTML(f"""
125
+ <iframe
126
+ id="fullscreen-iframe"
127
+ src="https://minicpm-omni.openbmb.cn/"
128
+ allowfullscreen
129
+ allow="camera; microphone; autoplay; encrypted-media; fullscreen; display-capture; geolocation"
130
+ title="LiveKit 实时音视频对话"
131
+ onload="console.log('🎙️ LiveKit 应用在 Hugging Face 中加载完成');"
132
+ onerror="console.error('❌ LiveKit 应用加载失败');">
133
+ </iframe>
134
+
135
+ <!-- 隐藏的信息面板,按 I 键显示 -->
136
+ <div id="info-panel" style="position: fixed; top: 10px; left: 10px; background: rgba(0,0,0,0.8); color: white; padding: 15px; border-radius: 10px; font-size: 12px; z-index: 999999; display: none;">
137
+ <h4 style="margin: 0 0 10px 0;">🎙️ LiveKit 实时音视频对话</h4>
138
+ <p style="margin: 5px 0;">🏠 Hugging Face Space: {space_id}</p>
139
+ <p style="margin: 5px 0;">🌐 嵌入应用: minicpm-omni.openbmb.cn/</p>
140
+ <p style="margin: 5px 0;">⌨️ 快捷键:</p>
141
+ <p style="margin: 2px 0 2px 20px;">• 0 - 音频模式</p>
142
+ <p style="margin: 2px 0 2px 20px;">• 1 - 视频模式</p>
143
+ <p style="margin: 2px 0 2px 20px;">• R - 刷新应用</p>
144
+ <p style="margin: 2px 0 2px 20px;">• I - 显示/隐藏此面板</p>
145
+ </div>
146
+
147
+ <script>
148
+ // I 键显示/隐藏信息面板
149
+ document.addEventListener('keydown', function(e) {{
150
+ if (e.key === 'i' || e.key === 'I') {{
151
+ const panel = document.querySelector('#info-panel');
152
+ if (panel) {{
153
+ panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
154
+ }}
155
+ }}
156
+ }});
157
+ </script>
158
+ """, show_label=False)
159
+
160
+ return demo
161
+
162
+ if __name__ == "__main__":
163
+ demo = main()
164
+
165
+ print("🎙️ LiveKit Hugging Face Spaces 版本")
166
+ print("=" * 50)
167
+ print("🌐 嵌入应用: https://minicpm-omni.openbmb.cn/")
168
+ print("🚀 部署平台: Hugging Face Spaces")
169
+ print("📱 访问地址: http://localhost:7860")
170
+ print("⌨️ 快捷键: 0(音频) 1(视频) R(刷新) I(信息)")
171
+ print("=" * 50)
172
+
173
+ # Hugging Face Spaces 部署配置
174
+ demo.launch(
175
+ server_name="0.0.0.0",
176
+ server_port=7860,
177
+ share=False,
178
+ show_error=True,
179
+ # Hugging Face Spaces 优化配置
180
+ )
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=4.0.0
2
+ requests>=2.28.0