aaappp7878 commited on
Commit
142ac3f
·
verified ·
1 Parent(s): 443a961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -17,7 +17,7 @@ os.makedirs("/tmp/transformers_cache", exist_ok=True)
17
  os.makedirs("/tmp/hf_home", exist_ok=True)
18
 
19
  #############################################
20
- # 模型管理部分 (原 optimized_model_loading.py)
21
  #############################################
22
 
23
  class ModelManager:
@@ -165,8 +165,9 @@ class ModelManager:
165
  return float(probabilities[0][predicted_class_idx].item())
166
  else:
167
  return 1 - float(probabilities[0][predicted_class_idx].item())
 
168
  #############################################
169
- # 特征提取部分 (原 optimized_feature_extraction.py)
170
  #############################################
171
 
172
  class FeatureExtractor:
@@ -485,7 +486,7 @@ class FeatureExtractor:
485
  freq_blocks.append(np.mean(magnitude * mask))
486
  features["freq_anisotropy"] = float(np.std(freq_blocks))
487
  #############################################
488
- # 分析逻辑部分 (原 optimized_app.py)
489
  #############################################
490
 
491
  # 初始化管理器
@@ -599,6 +600,9 @@ def get_detailed_analysis(ai_probability, ps_score, beauty_score, ps_signs, ai_s
599
  elif valid_models_count == 1:
600
  confidence_prefix = "中等置信度:"
601
 
 
 
 
602
  # 处理特征与模型判断不一致的情况
603
  if ai_feature_score > 0.8 and ai_probability < 0.6:
604
  ai_probability = max(0.8, ai_probability)
@@ -615,8 +619,6 @@ def get_detailed_analysis(ai_probability, ps_score, beauty_score, ps_signs, ai_s
615
  main_category = "AI生成"
616
  else:
617
  # 第二级分类:素人 vs 修图
618
- combined_edit_score = max(ps_score, beauty_score)
619
-
620
  if combined_edit_score > 0.5:
621
  category = confidence_prefix + "真人照片,修图痕迹明显"
622
  description = "图像基本是真人照片,但经过了明显的后期处理或美颜,修饰痕迹明显。"
@@ -638,7 +640,6 @@ def get_detailed_analysis(ai_probability, ps_score, beauty_score, ps_signs, ai_s
638
  beauty_details = "检测到的美颜特征:" + "、".join(beauty_signs) if beauty_signs else "未检测到明显的美颜特征。"
639
 
640
  return category, description, ps_details, ai_details, beauty_details, main_category
641
-
642
  def detect_ai_image(image):
643
  """Main detection function with optimizations"""
644
  if image is None:
@@ -768,5 +769,4 @@ iface = gr.Interface(
768
  )
769
 
770
  # 启动应用
771
- if __name__ == "__main__":
772
- iface.launch(share=True)
 
17
  os.makedirs("/tmp/hf_home", exist_ok=True)
18
 
19
  #############################################
20
+ # 模型管理部分
21
  #############################################
22
 
23
  class ModelManager:
 
165
  return float(probabilities[0][predicted_class_idx].item())
166
  else:
167
  return 1 - float(probabilities[0][predicted_class_idx].item())
168
+
169
  #############################################
170
+ # 特征提取部分
171
  #############################################
172
 
173
  class FeatureExtractor:
 
486
  freq_blocks.append(np.mean(magnitude * mask))
487
  features["freq_anisotropy"] = float(np.std(freq_blocks))
488
  #############################################
489
+ # 分析逻辑部分
490
  #############################################
491
 
492
  # 初始化管理器
 
600
  elif valid_models_count == 1:
601
  confidence_prefix = "中等置信度:"
602
 
603
+ # 计算编辑分数(在所有路径中都需要)
604
+ combined_edit_score = max(ps_score, beauty_score)
605
+
606
  # 处理特征与模型判断不一致的情况
607
  if ai_feature_score > 0.8 and ai_probability < 0.6:
608
  ai_probability = max(0.8, ai_probability)
 
619
  main_category = "AI生成"
620
  else:
621
  # 第二级分类:素人 vs 修图
 
 
622
  if combined_edit_score > 0.5:
623
  category = confidence_prefix + "真人照片,修图痕迹明显"
624
  description = "图像基本是真人照片,但经过了明显的后期处理或美颜,修饰痕迹明显。"
 
640
  beauty_details = "检测到的美颜特征:" + "、".join(beauty_signs) if beauty_signs else "未检测到明显的美颜特征。"
641
 
642
  return category, description, ps_details, ai_details, beauty_details, main_category
 
643
  def detect_ai_image(image):
644
  """Main detection function with optimizations"""
645
  if image is None:
 
769
  )
770
 
771
  # 启动应用
772
+ iface.launch(share=True)