YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
import streamlit as st import numpy as np import librosa import librosa.display import cv2 import tempfile import os from deepface import DeepFace
📌 Fonction pour calculer le score de dopamine
def dopamine_score(video_metrics): """ Calcule le score de dopamine d'une vidéo en fonction de plusieurs critères. """ weights = { "hook_strength": 20, "cuts_per_sec": 15, "emotion_intensity": 15, "cliffhangers": 10, "dopamine_words": 10, "visual_stimulation": 10, "cta_strength": 10, "narrative_structure": 5, "audio_intensity": 10, "facial_expressions": 10, "retention_rate": 10 } normalized_metrics = {key: min(1, max(0, video_metrics.get(key, 0))) for key in weights.keys()} total_score = sum(normalized_metrics[key] * weights[key] for key in weights) max_possible_score = sum(weights.values()) dopamine_score = round((total_score / max_possible_score) * 100, 2) return dopamine_score, normalized_metrics
📌 Analyse de l'audio pour évaluer l'intensité
def analyze_audio(audio_path): try: y, sr = librosa.load(audio_path) intensity = np.mean(librosa.feature.rms(y=y)) return min(1, intensity * 10) except Exception: return 0 # Retourne un score faible si l'analyse échoue
📌 Analyse des expressions faciales dans la vidéo
def analyze_facial_expressions(video_path): cap = cv2.VideoCapture(video_path) emotions_detected = [] while cap.isOpened(): ret, frame = cap.read() if not ret: break try: analysis = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False) emotions_detected.append(analysis[0]['dominant_emotion']) except: pass cap.release() emotion_strength = emotions_detected.count('happy') + emotions_detected.count('surprise') return min(1, emotion_strength / len(emotions_detected) if emotions_detected else 0)
📌 Analyse complète de la vidéo
def analyze_video_metrics(video_path, audio_path): video_data = { "hook_strength": 0.9, "cuts_per_sec": 0.8, "emotion_intensity": 0.7, "cliffhangers": 0.6, "dopamine_words": 0.7, "visual_stimulation": 0.8, "cta_strength": 0.9, "narrative_structure": 0.7, "audio_intensity": analyze_audio(audio_path), "facial_expressions": analyze_facial_expressions(video_path), "retention_rate": 0.8 } return dopamine_score(video_data)
📌 Interface Streamlit
st.title("📊 Dopamine Score Analyzer for Videos")
📌 Upload des fichiers vidéo et audio
uploaded_video = st.file_uploader("Upload your video file", type=["mp4", "mov", "avi"]) uploaded_audio = st.file_uploader("Upload the corresponding audio file", type=["wav", "mp3"])
if uploaded_video and uploaded_audio: with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video: temp_video.write(uploaded_video.read()) video_path = temp_video.name with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio: temp_audio.write(uploaded_audio.read()) audio_path = temp_audio.name
score, details = analyze_video_metrics(video_path, audio_path)
st.subheader(f"🔥 Dopamine Score: {score}/100")
for key, value in details.items():
st.write(f"{key.replace('_', ' ').title()}: {value * 100}%")
os.unlink(video_path)
os.unlink(audio_path)