pathananas commited on
Commit
d28d9e8
ยท
verified ยท
1 Parent(s): c5fa8f3

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +77 -21
model.py CHANGED
@@ -77,21 +77,15 @@ Prediction: **{text_label}**
77
 
78
  Confidence: **{text_conf}%**
79
  """
80
-
81
  except Exception as e:
82
  text_result_display = f"Text error: {str(e)}"
83
 
84
  # ================= IMAGE =================
85
- image_path = None
86
  if image is not None:
87
  try:
88
-
89
- # create image folder if not exists
90
-
91
  results = image_pipeline(image)
92
 
93
  image_result_display = "## ๐Ÿ–ผ Image Classification\n\n"
94
-
95
 
96
  for r in results[:3]:
97
  label = r["label"]
@@ -101,10 +95,6 @@ Confidence: **{text_conf}%**
101
  image_label = results[0]["label"]
102
  image_conf = round(results[0]["score"] * 100, 2)
103
 
104
- # image preview
105
-
106
-
107
-
108
  except Exception as e:
109
  image_result_display = f"Image error: {str(e)}"
110
 
@@ -139,37 +129,103 @@ Confidence: **{audio_conf}%**
139
  except Exception as e:
140
  audio_result_display = f"Audio error: {str(e)}"
141
 
142
- # ================= FUSION =================
143
- fusion_score, reasoning, interpretation, color = compute_fusion(
144
- text_label, text_conf,
145
- image_label, image_conf,
146
- audio_label, audio_conf
147
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  processing_time = round(time.time() - start_time, 2)
150
 
 
 
151
  fusion_summary = f"""
 
 
 
 
152
  <h2>๐Ÿ”Ž Multimodal Intelligence Summary</h2>
153
 
154
- {"<br>".join(reasoning)}
155
 
156
  <hr>
157
 
158
- <h3>Fusion Score</h3>
159
- <span style="color:{color}; font-size:24px; font-weight:bold;">
 
 
 
160
  {round(fusion_score,2)}
161
  </span>
 
162
  <hr>
163
 
164
- <h3>Interpretation</h3>
165
 
166
- {interpretation}
167
 
168
  <br>
169
 
170
  โฑ Processing Time: {processing_time} sec
 
 
171
  """
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  # ================= SAVE HISTORY =================
174
  save_analysis({
175
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
 
77
 
78
  Confidence: **{text_conf}%**
79
  """
 
80
  except Exception as e:
81
  text_result_display = f"Text error: {str(e)}"
82
 
83
  # ================= IMAGE =================
 
84
  if image is not None:
85
  try:
 
 
 
86
  results = image_pipeline(image)
87
 
88
  image_result_display = "## ๐Ÿ–ผ Image Classification\n\n"
 
89
 
90
  for r in results[:3]:
91
  label = r["label"]
 
95
  image_label = results[0]["label"]
96
  image_conf = round(results[0]["score"] * 100, 2)
97
 
 
 
 
 
98
  except Exception as e:
99
  image_result_display = f"Image error: {str(e)}"
100
 
 
129
  except Exception as e:
130
  audio_result_display = f"Audio error: {str(e)}"
131
 
132
+ # ================= FUSION REASONING =================
133
+
134
+ reasoning_lines = []
135
+
136
+ if text_label:
137
+ reasoning_lines.append(
138
+ f"The textual input expresses a {text_label.lower()} emotional tone ({text_conf}% confidence)."
139
+ )
140
+
141
+ if image_label:
142
+ reasoning_lines.append(
143
+ f"The uploaded image is most likely '{image_label}' ({image_conf}% confidence)."
144
+ )
145
+
146
+ if transcription:
147
+ reasoning_lines.append(
148
+ "The audio transcription indicates spoken conversational content."
149
+ )
150
+
151
+ # ================= FUSION SCORE =================
152
+
153
+ fusion_score = 0
154
+
155
+ if text_label == "POSITIVE":
156
+ fusion_score += text_conf * 0.5
157
+ elif text_label == "NEGATIVE":
158
+ fusion_score -= text_conf * 0.5
159
+
160
+ if image_label:
161
+ fusion_score += image_conf * 0.3
162
+
163
+ if transcription:
164
+ fusion_score += 20
165
+
166
+ # ================= INTERPRETATION =================
167
+
168
+ if fusion_score > 60:
169
+ alignment_message = "Multimodal signals align toward a positive and confident contextual interpretation."
170
+ color = "#22c55e"
171
+
172
+ elif fusion_score < 0:
173
+ alignment_message = "Multimodal signals indicate a potentially negative contextual alignment."
174
+ color = "#ef4444"
175
+
176
+ else:
177
+ alignment_message = "Multimodal signals are contextually mixed or neutral."
178
+ color = "#f59e0b"
179
 
180
  processing_time = round(time.time() - start_time, 2)
181
 
182
+ # ================= DISPLAY SUMMARY =================
183
+
184
  fusion_summary = f"""
185
+ <div style="padding:20px;border-radius:16px;
186
+ background:linear-gradient(135deg,#0f172a,#1e293b);
187
+ border:1px solid #1f2a44;">
188
+
189
  <h2>๐Ÿ”Ž Multimodal Intelligence Summary</h2>
190
 
191
+ {"<br>".join(reasoning_lines)}
192
 
193
  <hr>
194
 
195
+ <h3>๐Ÿ“Š Fusion Score</h3>
196
+
197
+ <span style="color:{color};
198
+ font-size:32px;
199
+ font-weight:700;">
200
  {round(fusion_score,2)}
201
  </span>
202
+
203
  <hr>
204
 
205
+ <h3>๐Ÿง  Interpretation</h3>
206
 
207
+ {alignment_message}
208
 
209
  <br>
210
 
211
  โฑ Processing Time: {processing_time} sec
212
+
213
+ </div>
214
  """
215
 
216
+ # ================= SAVE HISTORY =================
217
+
218
+ save_analysis({
219
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
220
+ "text": text,
221
+ "image": image_label,
222
+ "audio": audio_label,
223
+ "transcription": transcription,
224
+ "fusion_score": round(fusion_score, 2)
225
+ })
226
+
227
+ return fusion_summary, text_result_display, image_result_display, audio_result_display
228
+
229
  # ================= SAVE HISTORY =================
230
  save_analysis({
231
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),