|
|
|
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
NOTIFICATION_SETTINGS = { |
|
|
'show_success': True, |
|
|
'show_warnings': True, |
|
|
'show_errors': True, |
|
|
'auto_dismiss': True, |
|
|
'info_duration': 3.0, |
|
|
'error_duration': 5.0 |
|
|
} |
|
|
|
|
|
def notify_success(message): |
|
|
"""成功通知""" |
|
|
if NOTIFICATION_SETTINGS['show_success']: |
|
|
duration = NOTIFICATION_SETTINGS['info_duration'] |
|
|
return gr.Info(message, duration=duration) |
|
|
return None |
|
|
|
|
|
def notify_warning(message): |
|
|
"""警告通知""" |
|
|
if NOTIFICATION_SETTINGS['show_warnings']: |
|
|
duration = NOTIFICATION_SETTINGS['info_duration'] |
|
|
return gr.Warning(message, duration=duration) |
|
|
return None |
|
|
|
|
|
def notify_error(message): |
|
|
"""エラー通知""" |
|
|
if NOTIFICATION_SETTINGS['show_errors']: |
|
|
duration = NOTIFICATION_SETTINGS['error_duration'] |
|
|
return gr.Error(message, duration=duration) |
|
|
return None |
|
|
|
|
|
def notify_progress(message, progress=None): |
|
|
"""進捗通知""" |
|
|
if progress is not None: |
|
|
|
|
|
try: |
|
|
return gr.Progress(progress, desc=message) |
|
|
except: |
|
|
|
|
|
return gr.Info(f"{message} ({int(progress*100)}%)") |
|
|
else: |
|
|
return gr.Info(message) |
|
|
|
|
|
def configure_notifications(settings): |
|
|
"""通知設定の更新""" |
|
|
global NOTIFICATION_SETTINGS |
|
|
NOTIFICATION_SETTINGS.update(settings) |
|
|
return NOTIFICATION_SETTINGS |
|
|
|
|
|
|
|
|
class NotificationMessages: |
|
|
|
|
|
MODEL_LOADED = "DWPoseモデル読み込み完了" |
|
|
POSE_DETECTED = "ポーズ検出完了" |
|
|
IMAGE_UPLOADED = "画像アップロード完了" |
|
|
CANVAS_UPDATED = "キャンバス更新完了" |
|
|
|
|
|
|
|
|
NO_PERSON_DETECTED = "人物が検出されませんでした。別の画像をお試しください" |
|
|
MODEL_LOADING = "モデル読み込み中です。しばらくお待ちください" |
|
|
|
|
|
|
|
|
MODEL_LOAD_FAILED = "モデルの読み込みに失敗しました" |
|
|
POSE_DETECTION_FAILED = "ポーズ検出に失敗しました" |
|
|
IMAGE_PROCESSING_FAILED = "画像処理に失敗しました" |
|
|
NETWORK_ERROR = "ネットワークエラーが発生しました" |
|
|
|
|
|
|
|
|
def detect_pose_with_progress(detector, image): |
|
|
"""進捗表示付きポーズ検出""" |
|
|
try: |
|
|
notify_progress("画像を処理中...", 0.1) |
|
|
|
|
|
|
|
|
notify_progress("画像前処理中...", 0.2) |
|
|
|
|
|
|
|
|
notify_progress("人物を検出中...", 0.4) |
|
|
|
|
|
|
|
|
notify_progress("ポーズを解析中...", 0.7) |
|
|
|
|
|
|
|
|
result = detector.detect(image) |
|
|
|
|
|
notify_progress("完了", 1.0) |
|
|
return result |
|
|
|
|
|
except Exception as e: |
|
|
notify_error(f"処理中にエラーが発生しました: {str(e)}") |
|
|
return None, str(e) |