pathananas commited on
Commit
4e6b70b
·
verified ·
1 Parent(s): aa0e038

Update models.py

Browse files
Files changed (1) hide show
  1. models.py +7 -51
models.py CHANGED
@@ -1,11 +1,12 @@
1
  # ==============================
2
- # MODEL + FUSION LOGIC
3
  # ==============================
4
 
5
  from transformers import pipeline
6
  import torch
7
  import time
8
  from datetime import datetime
 
9
 
10
  device = 0 if torch.cuda.is_available() else -1
11
 
@@ -126,58 +127,13 @@ def multimodal_analyze(text, image, audio):
126
  """
127
  except Exception as e:
128
  audio_result_display = f"Audio processing error: {str(e)}"
129
- audio_label = None
130
- audio_conf = 0
131
 
132
  # -------- FUSION --------
133
- reasoning_lines = []
134
- fusion_score = 0
135
- total_weight = 0
136
-
137
- if text_label:
138
- reasoning_lines.append(
139
- f"Text suggests a {text_label.lower()} tone ({text_conf}%)."
140
- )
141
- weight = 0.4
142
- fusion_score += text_conf * weight if text_label == "POSITIVE" else -text_conf * weight
143
- total_weight += weight
144
-
145
- if audio_label:
146
- reasoning_lines.append(
147
- f"Spoken content carries a {audio_label.lower()} tone ({audio_conf}%)."
148
- )
149
- weight = 0.35
150
- fusion_score += audio_conf * weight if audio_label == "POSITIVE" else -audio_conf * weight
151
- total_weight += weight
152
-
153
- if image_label and image_conf > 40:
154
- reasoning_lines.append(
155
- f"Image classified as {image_label} ({image_conf}%)."
156
- )
157
- weight = 0.25
158
- fusion_score += image_conf * weight
159
- total_weight += weight
160
-
161
- if total_weight > 0:
162
- fusion_score = fusion_score / total_weight
163
-
164
- fusion_score = max(min(fusion_score, 100), -100)
165
-
166
- if fusion_score > 60:
167
- alignment_message = "Strong positive multimodal alignment detected."
168
- color = "#22c55e"
169
- elif fusion_score > 20:
170
- alignment_message = "Moderate positive contextual signals observed."
171
- color = "#facc15"
172
- elif fusion_score > -20:
173
- alignment_message = "Mixed or neutral signals across modalities."
174
- color = "#94a3b8"
175
- elif fusion_score > -60:
176
- alignment_message = "Moderate negative contextual alignment detected."
177
- color = "#f97316"
178
- else:
179
- alignment_message = "Strong negative multimodal alignment detected."
180
- color = "#ef4444"
181
 
182
  processing_time = round(time.time() - start_time, 2)
183
 
 
1
  # ==============================
2
+ # MODEL + MODALITY PROCESSING
3
  # ==============================
4
 
5
  from transformers import pipeline
6
  import torch
7
  import time
8
  from datetime import datetime
9
+ from fusion import compute_fusion
10
 
11
  device = 0 if torch.cuda.is_available() else -1
12
 
 
127
  """
128
  except Exception as e:
129
  audio_result_display = f"Audio processing error: {str(e)}"
 
 
130
 
131
  # -------- FUSION --------
132
+ fusion_score, reasoning_lines, alignment_message, color = compute_fusion(
133
+ text_label, text_conf,
134
+ image_label, image_conf,
135
+ audio_label, audio_conf
136
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  processing_time = round(time.time() - start_time, 2)
139