Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,30 +5,23 @@ from text import analyze_text # 从 text.py 导入
|
|
| 5 |
from video import analyze_video # 从 video.py 导入
|
| 6 |
from audio import analyze_audio # 从 audio.py 导入
|
| 7 |
|
| 8 |
-
def process_file(file):
|
| 9 |
-
try:
|
| 10 |
-
# 检测文件类型
|
| 11 |
-
file_type = magic.from_buffer(file.read(1024), mime=True).split('/')[0]
|
| 12 |
-
file.seek(0)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
except Exception as e:
|
| 30 |
-
return
|
| 31 |
-
|
| 32 |
|
| 33 |
# 构建交互界面
|
| 34 |
import gradio as gr
|
|
@@ -44,7 +37,7 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="sm")) as app:
|
|
| 44 |
with gr.Column(scale=2):
|
| 45 |
file_input = gr.File(
|
| 46 |
label="📁 Upload File (Text / Video / Audio)",
|
| 47 |
-
file_types=[".pdf", ".docx", ".txt", ".mp4", ".mov", ".wav", ".mp3", ".m4a"]
|
| 48 |
type="filepath" # ✅ 返回路径字符串,而不是 NamedString/File 对象
|
| 49 |
)
|
| 50 |
with gr.Column(scale=3):
|
|
@@ -56,23 +49,6 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="sm")) as app:
|
|
| 56 |
|
| 57 |
analyze_btn = gr.Button("🔍 Analyze Content", variant="primary")
|
| 58 |
output = gr.Markdown()
|
| 59 |
-
|
| 60 |
-
def process_input(file, text):
|
| 61 |
-
# 输入优先级: 文件 > 文本
|
| 62 |
-
if file:
|
| 63 |
-
try:
|
| 64 |
-
ctext, lang = extract_text(file) # ✅ 提取文本 + 自动识别语言
|
| 65 |
-
except Exception as e:
|
| 66 |
-
return f"❌ File parsing failed: {str(e)}"
|
| 67 |
-
elif text.strip():
|
| 68 |
-
content = text
|
| 69 |
-
else:
|
| 70 |
-
return "⚠️ Please upload a file or input text"
|
| 71 |
-
|
| 72 |
-
try:
|
| 73 |
-
return analyze_text(content)
|
| 74 |
-
except Exception as e:
|
| 75 |
-
return f"🔥 Analysis error: {str(e)}"
|
| 76 |
|
| 77 |
analyze_btn.click(
|
| 78 |
fn=process_input,
|
|
|
|
| 5 |
from video import analyze_video # 从 video.py 导入
|
| 6 |
from audio import analyze_audio # 从 audio.py 导入
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def process_input(file, text):
|
| 10 |
+
# 输入优先级: 文件 > 文本
|
| 11 |
+
if file:
|
| 12 |
+
try:
|
| 13 |
+
ctext, lang = extract_text(file) # ✅ 提取文本 + 自动识别语言
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"❌ File parsing failed: {str(e)}"
|
| 16 |
+
elif text.strip():
|
| 17 |
+
content = text
|
| 18 |
+
else:
|
| 19 |
+
return "⚠️ Please upload a file or input text"
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
return analyze_text(text, lang)
|
|
|
|
| 23 |
except Exception as e:
|
| 24 |
+
return f"🔥 Analysis error: {str(e)}"
|
|
|
|
| 25 |
|
| 26 |
# 构建交互界面
|
| 27 |
import gradio as gr
|
|
|
|
| 37 |
with gr.Column(scale=2):
|
| 38 |
file_input = gr.File(
|
| 39 |
label="📁 Upload File (Text / Video / Audio)",
|
| 40 |
+
file_types=[".pdf", ".docx", ".txt", ".mp4", ".mov", ".wav", ".mp3", ".m4a"],
|
| 41 |
type="filepath" # ✅ 返回路径字符串,而不是 NamedString/File 对象
|
| 42 |
)
|
| 43 |
with gr.Column(scale=3):
|
|
|
|
| 49 |
|
| 50 |
analyze_btn = gr.Button("🔍 Analyze Content", variant="primary")
|
| 51 |
output = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
analyze_btn.click(
|
| 54 |
fn=process_input,
|