Spaces:
Sleeping
Sleeping
model.py
Browse files
model.py
CHANGED
|
@@ -8,7 +8,7 @@ from transformers import pipeline
|
|
| 8 |
from fusion import compute_fusion
|
| 9 |
import torch
|
| 10 |
import time
|
| 11 |
-
|
| 12 |
torch.set_grad_enabled(False)
|
| 13 |
|
| 14 |
device = 0 if torch.cuda.is_available() else -1
|
|
@@ -85,6 +85,13 @@ Confidence: **{text_conf}%**
|
|
| 85 |
if image is not None:
|
| 86 |
try:
|
| 87 |
results = image_pipeline(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
image_result_display = "## 🖼 Image Classification\n\n"
|
| 90 |
|
|
@@ -170,6 +177,7 @@ Confidence: **{audio_conf}%**
|
|
| 170 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 171 |
"text": text,
|
| 172 |
"image": image_label,
|
|
|
|
| 173 |
"audio": audio_label,
|
| 174 |
"transcription": transcription,
|
| 175 |
"fusion_score": round(fusion_score,2)
|
|
|
|
| 8 |
from fusion import compute_fusion
|
| 9 |
import torch
|
| 10 |
import time
|
| 11 |
+
import os
|
| 12 |
torch.set_grad_enabled(False)
|
| 13 |
|
| 14 |
device = 0 if torch.cuda.is_available() else -1
|
|
|
|
| 85 |
if image is not None:
|
| 86 |
try:
|
| 87 |
results = image_pipeline(image)
|
| 88 |
+
# create image folder if not exists
|
| 89 |
+
os.makedirs("saved_images", exist_ok=True)
|
| 90 |
+
|
| 91 |
+
image_path = None
|
| 92 |
+
if image is not None:
|
| 93 |
+
image_path = f"saved_images/{int(time.time())}.png"
|
| 94 |
+
image.save(image_path)
|
| 95 |
|
| 96 |
image_result_display = "## 🖼 Image Classification\n\n"
|
| 97 |
|
|
|
|
| 177 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 178 |
"text": text,
|
| 179 |
"image": image_label,
|
| 180 |
+
"image_path": image_path,
|
| 181 |
"audio": audio_label,
|
| 182 |
"transcription": transcription,
|
| 183 |
"fusion_score": round(fusion_score,2)
|