Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
import torch
|
3 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification, Trainer, TrainingArguments
|
4 |
from PIL import Image
|
@@ -86,7 +86,7 @@ def retrain_model(feedback_data):
|
|
86 |
|
87 |
dataset_dict = {
|
88 |
"image": [load_image(f) for f in feedback_data["image_path"]],
|
89 |
-
"label": feedback_data["correct_label"].tolist()
|
90 |
}
|
91 |
|
92 |
dataset = Dataset.from_dict(dataset_dict)
|
@@ -95,7 +95,7 @@ def retrain_model(feedback_data):
|
|
95 |
# Preprocess the dataset
|
96 |
def preprocess(examples):
|
97 |
inputs = feature_extractor(images=examples["image"], return_tensors="pt")
|
98 |
-
inputs["labels"] = examples["label"]
|
99 |
return inputs
|
100 |
|
101 |
dataset = dataset.with_transform(preprocess)
|
|
|
1 |
+
iimport gradio as gr
|
2 |
import torch
|
3 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification, Trainer, TrainingArguments
|
4 |
from PIL import Image
|
|
|
86 |
|
87 |
dataset_dict = {
|
88 |
"image": [load_image(f) for f in feedback_data["image_path"]],
|
89 |
+
"label": [str(lbl) for lbl in feedback_data["correct_label"].tolist()]
|
90 |
}
|
91 |
|
92 |
dataset = Dataset.from_dict(dataset_dict)
|
|
|
95 |
# Preprocess the dataset
|
96 |
def preprocess(examples):
|
97 |
inputs = feature_extractor(images=examples["image"], return_tensors="pt")
|
98 |
+
inputs["labels"] = [int(lbl) for lbl in examples["label"]]
|
99 |
return inputs
|
100 |
|
101 |
dataset = dataset.with_transform(preprocess)
|