Dhrubob commited on
Commit
4e3aed3
Β·
verified Β·
1 Parent(s): 5a60f42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -30
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from transformers import pipeline
3
  from datetime import datetime
4
  import random
5
- import os
6
 
7
  # -------------------------------------------------
8
  # 🎯 MODEL INITIALIZATION
@@ -43,7 +42,6 @@ def analyze_emotion(audio, team, purpose):
43
  label, emoji, color = EMOTION_MAP.get(top["label"], (top["label"], "🎭", "#607d8b"))
44
  score = round(top["score"] * 100, 2)
45
 
46
- # Dashboard HTML
47
  dashboard_html = f"""
48
  <div style="text-align:center; padding:15px;">
49
  <h2>🏒 <b>{team}</b> | 🎯 <b>{purpose}</b></h2>
@@ -79,15 +77,14 @@ def analyze_emotion(audio, team, purpose):
79
  <p style="font-size:13px; color:#777;">(Demo mode β€” not stored to any database)</p>
80
  </div>
81
  """
82
-
83
  return dashboard_html, insight_html
84
 
85
 
86
  # -------------------------------------------------
87
- # 🎨 GRADIO INTERFACE
88
  # -------------------------------------------------
89
- DEPARTMENTS = ["Test","Procurement", "Logistics", "Planning", "Inventory", "Distribution", "HR", "Other"]
90
- PURPOSES = ["Test","HR Meeting", "Team Stand-up", "One-on-One", "Customer Call", "Interview", "Other"]
91
 
92
  disclaimer_html = """
93
  <div style="display:flex; align-items:center; background:linear-gradient(135deg, #fff8e1, #fff3cd);
@@ -110,21 +107,21 @@ disclaimer_html = """
110
  """
111
 
112
  # -------------------------------------------------
113
- # πŸš€ APP UI WITH LOADING INDICATOR
114
  # -------------------------------------------------
115
  with gr.Blocks(theme=gr.themes.Soft()) as app:
116
  gr.HTML("""
117
  <div style="text-align:center; padding:20px;">
118
  <h1>🎧 SCM Emotion Intelligence Dashboard</h1>
119
  <p style="font-size:16px; color:#555;">
120
- Analyze live or uploaded audio from meetings to understand emotional tone within teams.<br>
121
- Built for HR & Managers to assess engagement and team well-being.
122
  </p>
123
  </div>
124
  """)
125
 
126
- with gr.Row():
127
- with gr.Column(scale=1, min_width=350):
128
  audio_input = gr.Audio(
129
  sources=["microphone", "upload"],
130
  type="filepath",
@@ -134,36 +131,33 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
134
  purpose_input = gr.Dropdown(PURPOSES, label="🎯 Purpose of Audio")
135
  analyze_btn = gr.Button("πŸš€ Analyze Emotion", variant="primary")
136
 
137
- # πŸ”„ Loading animation message
138
- loading_msg = gr.HTML(
139
- "<div style='text-align:center; color:#999; font-size:15px;'>Waiting for input...</div>"
140
- )
141
-
142
  gr.HTML(disclaimer_html)
143
 
144
- with gr.Column(scale=2, min_width=500):
145
- output_html = gr.HTML()
 
 
 
 
146
  insight_html = gr.HTML()
147
 
148
- # When Analyze button clicked
149
- def process_with_loading(audio, team, purpose):
150
- loading_html = """
151
- <div style='text-align:center; padding:30px;'>
152
- <h3>⏳ Analyzing your audio...</h3>
153
- <p style='color:#666;'>This may take a few seconds depending on file size.</p>
154
  <div style='margin:auto; border:6px solid #eee; border-top:6px solid #4a90e2;
155
- border-radius:50%; width:40px; height:40px; animation:spin 1s linear infinite;'></div>
 
 
156
  <style>@keyframes spin {0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}</style>
157
  </div>
158
  """
159
- # Show loading first
160
- yield loading_html, None
161
- # Then run the model
162
  dashboard_html, insight_html = analyze_emotion(audio, team, purpose)
163
  yield dashboard_html, insight_html
164
 
165
  analyze_btn.click(
166
- fn=process_with_loading,
167
  inputs=[audio_input, team_input, purpose_input],
168
  outputs=[output_html, insight_html],
169
  )
@@ -171,9 +165,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
171
  gr.HTML("""
172
  <hr>
173
  <p style="text-align:center; color:#999; font-size:14px;">
174
- πŸ’Ύ (Demo Mode) Database integration coming soon for Power BI visualization.
 
175
  </p>
176
  """)
177
 
 
 
 
178
  if __name__ == "__main__":
179
  app.launch(server_name="0.0.0.0", server_port=7860)
 
2
  from transformers import pipeline
3
  from datetime import datetime
4
  import random
 
5
 
6
  # -------------------------------------------------
7
  # 🎯 MODEL INITIALIZATION
 
42
  label, emoji, color = EMOTION_MAP.get(top["label"], (top["label"], "🎭", "#607d8b"))
43
  score = round(top["score"] * 100, 2)
44
 
 
45
  dashboard_html = f"""
46
  <div style="text-align:center; padding:15px;">
47
  <h2>🏒 <b>{team}</b> | 🎯 <b>{purpose}</b></h2>
 
77
  <p style="font-size:13px; color:#777;">(Demo mode β€” not stored to any database)</p>
78
  </div>
79
  """
 
80
  return dashboard_html, insight_html
81
 
82
 
83
  # -------------------------------------------------
84
+ # 🎨 GRADIO UI ELEMENTS
85
  # -------------------------------------------------
86
+ DEPARTMENTS = ["Procurement", "Logistics", "Planning", "Inventory", "Distribution", "HR", "Other"]
87
+ PURPOSES = ["HR Meeting", "Team Stand-up", "One-on-One", "Customer Call", "Interview", "Other"]
88
 
89
  disclaimer_html = """
90
  <div style="display:flex; align-items:center; background:linear-gradient(135deg, #fff8e1, #fff3cd);
 
107
  """
108
 
109
  # -------------------------------------------------
110
+ # πŸš€ APP INTERFACE WITH INLINE LOADING
111
  # -------------------------------------------------
112
  with gr.Blocks(theme=gr.themes.Soft()) as app:
113
  gr.HTML("""
114
  <div style="text-align:center; padding:20px;">
115
  <h1>🎧 SCM Emotion Intelligence Dashboard</h1>
116
  <p style="font-size:16px; color:#555;">
117
+ Analyze uploaded or recorded team meeting audio to understand the emotional tone of employees.<br>
118
+ Built for HR and Managers to assess engagement and team well-being.
119
  </p>
120
  </div>
121
  """)
122
 
123
+ with gr.Row(equal_height=True):
124
+ with gr.Column(scale=1, min_width=380):
125
  audio_input = gr.Audio(
126
  sources=["microphone", "upload"],
127
  type="filepath",
 
131
  purpose_input = gr.Dropdown(PURPOSES, label="🎯 Purpose of Audio")
132
  analyze_btn = gr.Button("πŸš€ Analyze Emotion", variant="primary")
133
 
 
 
 
 
 
134
  gr.HTML(disclaimer_html)
135
 
136
+ with gr.Column(scale=2, min_width=550):
137
+ output_html = gr.HTML("""
138
+ <div style='text-align:center; padding:30px; color:#999;'>
139
+ <p>Awaiting input... Upload or record to begin analysis.</p>
140
+ </div>
141
+ """)
142
  insight_html = gr.HTML()
143
 
144
+ # Inline loader β€” replaces dashboard temporarily
145
+ def process_with_loader(audio, team, purpose):
146
+ loader_html = """
147
+ <div style='text-align:center; padding:60px;'>
 
 
148
  <div style='margin:auto; border:6px solid #eee; border-top:6px solid #4a90e2;
149
+ border-radius:50%; width:50px; height:50px; animation:spin 1s linear infinite;'></div>
150
+ <h3 style='color:#333; margin-top:20px;'>⏳ Analyzing your audio...</h3>
151
+ <p style='color:#777;'>This may take a few seconds depending on file size.</p>
152
  <style>@keyframes spin {0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}</style>
153
  </div>
154
  """
155
+ yield loader_html, None
 
 
156
  dashboard_html, insight_html = analyze_emotion(audio, team, purpose)
157
  yield dashboard_html, insight_html
158
 
159
  analyze_btn.click(
160
+ fn=process_with_loader,
161
  inputs=[audio_input, team_input, purpose_input],
162
  outputs=[output_html, insight_html],
163
  )
 
165
  gr.HTML("""
166
  <hr>
167
  <p style="text-align:center; color:#999; font-size:14px;">
168
+ πŸ’Ύ (Demo Mode) Database integration coming soon for Power BI visualization.<br>
169
+ Presented by <b>Dhrubo Bhattacharjee</b>
170
  </p>
171
  """)
172
 
173
+ # -------------------------------------------------
174
+ # 🏁 LAUNCH APP
175
+ # -------------------------------------------------
176
  if __name__ == "__main__":
177
  app.launch(server_name="0.0.0.0", server_port=7860)