logu29 commited on
Commit
be6a600
·
verified ·
1 Parent(s): 9fed135

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -6,14 +6,14 @@ import moviepy.editor as mp
6
  import tempfile
7
  import os
8
 
9
- # Sentiment analysis for text
10
  def analyze_text(text):
11
  blob = TextBlob(text)
12
- sentiment = blob.sentiment.polarity
13
- emotion = "Positive" if sentiment > 0 else "Negative" if sentiment < 0 else "Neutral"
14
- return f"Sentiment: {emotion} (Score: {sentiment:.2f})"
15
 
16
- # Emotion detection for image
17
  def analyze_face(image):
18
  try:
19
  result = DeepFace.analyze(image, actions=['emotion'], enforce_detection=False)
@@ -22,12 +22,12 @@ def analyze_face(image):
22
  except Exception as e:
23
  return f"Error analyzing face: {str(e)}"
24
 
25
- # Analyze emotion in video
26
  def analyze_video(video_path):
27
  try:
28
  temp_folder = tempfile.mkdtemp()
29
  clip = mp.VideoFileClip(video_path)
30
- frame = clip.get_frame(clip.duration / 2) # middle frame
31
  frame_path = os.path.join(temp_folder, "frame.jpg")
32
  cv2.imwrite(frame_path, cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
33
  result = DeepFace.analyze(frame_path, actions=['emotion'], enforce_detection=False)
@@ -36,7 +36,7 @@ def analyze_video(video_path):
36
  except Exception as e:
37
  return f"Error analyzing video: {str(e)}"
38
 
39
- # Create Gradio Interface
40
  with gr.Blocks() as demo:
41
  gr.Markdown("# 🧠 Emotion Decoder - Sentiment & Emotion Analysis")
42
 
@@ -61,4 +61,6 @@ with gr.Blocks() as demo:
61
  demo.launch()
62
 
63
 
 
 
64
 
 
6
  import tempfile
7
  import os
8
 
9
+ # Analyze text
10
  def analyze_text(text):
11
  blob = TextBlob(text)
12
+ polarity = blob.sentiment.polarity
13
+ emotion = "Positive" if polarity > 0 else "Negative" if polarity < 0 else "Neutral"
14
+ return f"Sentiment: {emotion} (Score: {polarity:.2f})"
15
 
16
+ # Analyze face
17
  def analyze_face(image):
18
  try:
19
  result = DeepFace.analyze(image, actions=['emotion'], enforce_detection=False)
 
22
  except Exception as e:
23
  return f"Error analyzing face: {str(e)}"
24
 
25
+ # Analyze video
26
  def analyze_video(video_path):
27
  try:
28
  temp_folder = tempfile.mkdtemp()
29
  clip = mp.VideoFileClip(video_path)
30
+ frame = clip.get_frame(clip.duration / 2)
31
  frame_path = os.path.join(temp_folder, "frame.jpg")
32
  cv2.imwrite(frame_path, cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
33
  result = DeepFace.analyze(frame_path, actions=['emotion'], enforce_detection=False)
 
36
  except Exception as e:
37
  return f"Error analyzing video: {str(e)}"
38
 
39
+ # Build Gradio Interface
40
  with gr.Blocks() as demo:
41
  gr.Markdown("# 🧠 Emotion Decoder - Sentiment & Emotion Analysis")
42
 
 
61
  demo.launch()
62
 
63
 
64
+
65
+
66