Mentosyevsky commited on
Commit
96e3a4b
·
verified ·
1 Parent(s): c895669

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 创建项目文件夹
2
+ mkdir multimodal-tool && cd multimodal-tool
3
+
4
+ # 转换 Jupyter 文件
5
+ jupyter nbconvert --to script video.ipynb
6
+ jupyter nbconvert --to script audio.ipynb
7
+
8
+ # 重命名文本分析模块
9
+ mv text.py text_analyzer.py
10
+
11
+
12
+ import gradio as gr
13
+ import magic
14
+ import tempfile
15
+ from text_analyzer import analyze_text # 从 text_analyzer.py 导入
16
+ from video import analyze_video # 从 video.py 导入
17
+ from audio import analyze_audio # 从 audio.py 导入
18
+
19
+ def process_file(file):
20
+ try:
21
+ # 检测文件类型
22
+ file_type = magic.from_buffer(file.read(1024), mime=True).split('/')[0]
23
+ file.seek(0)
24
+
25
+ # 保存临时文件
26
+ with tempfile.NamedTemporaryFile(suffix=file.name) as tmp:
27
+ tmp.write(file.read())
28
+ tmp.seek(0)
29
+
30
+ # 分发处理逻辑
31
+ if file_type == "text":
32
+ return analyze_text(tmp.name)
33
+ elif file_type == "video":
34
+ return analyze_video(tmp.name)
35
+ elif file_type == "audio":
36
+ return analyze_audio(tmp.name)
37
+ else:
38
+ return {"error": "Unsupported file type"}
39
+
40
+ except Exception as e:
41
+ return {"error": f"Processing failed: {str(e)}"}
42
+
43
+
44
+ # 构建交互界面
45
+ interface = gr.Interface(
46
+ fn=process_file,
47
+ inputs=gr.File(label="📁 upload file (support txt/mp3/mp4)"),
48
+ outputs=gr.JSON(label="🔍 analysis result"),
49
+ title="EthosAI - Media Integrity Toolkit",
50
+ description="We are an AI-driven tool focused on media analysis, designed to assist global media organizations in detecting and preventing inappropriate discourse, misinformation, and harmful content in reports related to refugees, migrants, and other displaced populations.",
51
+ allow_flagging="never"
52
+ )
53
+
54
+ # 启动应用
55
+ interface.launch(debug=True)