Sagnik1750 commited on
Commit
69a5273
Β·
verified Β·
1 Parent(s): 26e431e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -76,27 +76,36 @@ def process_video(input_path):
76
  plt.pie(sizes, labels=labels, autopct='%1.1f%%', colors=sns.color_palette('pastel'))
77
  plt.title("Emotion Distribution")
78
  plt.savefig("emotion_distribution.jpg")
79
- plt.close()
80
-
81
- return "output_video.mp4", "emotion_distribution.jpg", major_emotion
82
 
83
  # Gradio Web Interface
84
- gr.Interface(
85
- fn=process_video,
86
- inputs=gr.File(type="filepath"),
87
- outputs=[
88
- gr.File(label="Processed Video"),
89
- gr.File(label="Emotion Distribution Chart"),
90
- gr.Textbox(label="Major Emotion Detected")
91
- ],
92
- title="Emotion Detection from Video",
93
- description="Upload a video, and the AI will detect emotions in each frame, providing a processed video, an emotion distribution chart, and the major detected emotion.",
94
- css="""
95
- .gradio-container { max-width: 800px !important; margin: auto; }
96
- .gradio-container h1 { font-size: 22px; }
97
  @media screen and (max-width: 768px) {
98
  .gradio-container { width: 100%; padding: 10px; }
99
  .gradio-container h1 { font-size: 18px; }
100
  }
101
- """
102
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  plt.pie(sizes, labels=labels, autopct='%1.1f%%', colors=sns.color_palette('pastel'))
77
  plt.title("Emotion Distribution")
78
  plt.savefig("emotion_distribution.jpg")
79
+
80
+ return "output_video.mp4", plt, major_emotion
 
81
 
82
  # Gradio Web Interface
83
+ with gr.Blocks(css="""
84
+ .gradio-container { max-width: 750px !important; margin: auto; background-color: #f8f9fa; padding: 20px; border-radius: 15px; }
85
+ .gradio-container h1 { font-size: 22px; text-align: center; color: #333; }
86
+ .gradio-container .gr-button { background-color: #007bff; color: white; border-radius: 10px; padding: 8px 15px; }
87
+ .gradio-container .gr-textbox { font-size: 16px; font-weight: bold; color: #007bff; }
88
+ .gradio-container .gr-file { border-radius: 10px; padding: 5px; }
 
 
 
 
 
 
 
89
  @media screen and (max-width: 768px) {
90
  .gradio-container { width: 100%; padding: 10px; }
91
  .gradio-container h1 { font-size: 18px; }
92
  }
93
+ """) as demo:
94
+ gr.Markdown("# 🎭 Emotion Analysis from Video πŸŽ₯")
95
+ gr.Markdown("Upload a video, and the AI will detect emotions in each frame, providing a processed video, an emotion distribution chart, and the major detected emotion.")
96
+
97
+ with gr.Row():
98
+ video_input = gr.File(label="πŸ“€ Upload Video (MP4, MOV, AVI)")
99
+
100
+ with gr.Row():
101
+ process_button = gr.Button("πŸš€ Analyze")
102
+
103
+ with gr.Row():
104
+ video_output = gr.File(label="πŸ“₯ Processed Video")
105
+ emotion_chart = gr.Plot(label="πŸ“Š Emotion Distribution Chart")
106
+
107
+ major_emotion_output = gr.Textbox(label="πŸ”₯ Major Emotion Detected", interactive=False)
108
+
109
+ process_button.click(fn=process_video, inputs=video_input, outputs=[video_output, emotion_chart, major_emotion_output])
110
+
111
+ demo.launch()