Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,19 @@ chk_point = "kdhht2334/autotrain-diffusion-emotion-facial-expression-recognition
|
|
| 11 |
|
| 12 |
model = AutoModelForImageClassification.from_pretrained(chk_point)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
pipe = pipeline(
|
| 16 |
"image-classification",
|
|
@@ -24,34 +37,46 @@ except NotImplementedError:
|
|
| 24 |
pipe = pipeline("image-classification", chk_point, device=device)
|
| 25 |
|
| 26 |
|
| 27 |
-
def make_label_folders():
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
def predictions_into_folders(files):
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
demo = gr.Interface(
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
)
|
| 57 |
-
demo.launch(enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
model = AutoModelForImageClassification.from_pretrained(chk_point)
|
| 13 |
|
| 14 |
+
emotion_dict = {
|
| 15 |
+
'neutral': '0',
|
| 16 |
+
'happy': '1',
|
| 17 |
+
'sad' :'2',
|
| 18 |
+
'surprise': '3',
|
| 19 |
+
'fear': '4',
|
| 20 |
+
'disgust': '5',
|
| 21 |
+
'angry': '6',
|
| 22 |
+
'uncertain': '7',
|
| 23 |
+
'nonface': '8',
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
try:
|
| 28 |
pipe = pipeline(
|
| 29 |
"image-classification",
|
|
|
|
| 37 |
pipe = pipeline("image-classification", chk_point, device=device)
|
| 38 |
|
| 39 |
|
| 40 |
+
# def make_label_folders():
|
| 41 |
+
# folders = model.config.label2id.keys()
|
| 42 |
+
# for folder in folders:
|
| 43 |
+
# folder = Path(folder)
|
| 44 |
+
# if not folder.exists():
|
| 45 |
+
# folder.mkdir()
|
| 46 |
+
# return folders
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# def predictions_into_folders(files):
|
| 50 |
+
# files = [file.name for file in files]
|
| 51 |
+
# files = [
|
| 52 |
+
# file for file in files if not file.startswith(".") and "DS_Store" not in file
|
| 53 |
+
# ]
|
| 54 |
+
# folders = make_label_folders()
|
| 55 |
+
# predictions = pipe(files)
|
| 56 |
+
# for file, prediction in zip(files, predictions):
|
| 57 |
+
# label = prediction[0]["label"]
|
| 58 |
+
# file_name = Path(file).name
|
| 59 |
+
# shutil.copy(file, f"{label}/{file_name}")
|
| 60 |
+
# for folder in folders:
|
| 61 |
+
# shutil.make_archive(folder, "zip", ".", folder)
|
| 62 |
+
# return [f"{folder}.zip" for folder in folders]
|
| 63 |
+
|
| 64 |
+
# demo = gr.Interface(
|
| 65 |
+
# predictions_into_folders,
|
| 66 |
+
# gr.Files(file_count="directory", file_types=["image"]),
|
| 67 |
+
# gr.Files(),
|
| 68 |
+
# cache_examples=True,
|
| 69 |
+
# )
|
| 70 |
+
# demo.launch(enable_queue=True)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def predict(image):
|
| 74 |
+
predictions = pipe(image)
|
| 75 |
+
return {p["label"]: p["score"] for p in predictions}
|
| 76 |
+
|
| 77 |
+
gr.Interface(
|
| 78 |
+
predict,
|
| 79 |
+
inputs=gr.inputs.Image(label="Upload image", type="filepath"),
|
| 80 |
+
outputs=gr.outputs.Label(num_top_classes=7),
|
| 81 |
+
title="FER trained on DiffusionFER dataset",
|
| 82 |
+
).launch()
|