Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
### 1. Imports and class names setup
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import torch
|
|
@@ -8,15 +8,15 @@ from timeit import default_timer as timer
|
|
| 8 |
from typing import Tuple, Dict
|
| 9 |
|
| 10 |
# Setup class names
|
| 11 |
-
with open("class_names.txt", "r") as f: # reading
|
| 12 |
class_names = [food_name.strip() for food_name in f.readlines()]
|
| 13 |
|
| 14 |
-
### 2. Model and transforms preparation
|
| 15 |
|
| 16 |
# Create model
|
| 17 |
effnetb2, effnetb2_transforms = create_effnetb2_model(
|
| 18 |
-
num_classes=
|
| 19 |
-
)
|
| 20 |
|
| 21 |
# Load saved weights
|
| 22 |
effnetb2.load_state_dict(
|
|
@@ -56,18 +56,18 @@ def predict(img) -> Tuple[Dict, float]:
|
|
| 56 |
return pred_labels_and_probs, pred_time
|
| 57 |
|
| 58 |
|
| 59 |
-
### 4. Gradio app
|
| 60 |
|
| 61 |
-
# Create title, description and article
|
| 62 |
title = "FoodVision Big 🍔👁"
|
| 63 |
-
description = "
|
| 64 |
-
article = "Created
|
| 65 |
|
| 66 |
# Create examples list from "examples/" directory
|
| 67 |
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
| 68 |
|
| 69 |
-
# Create Gradio interface
|
| 70 |
-
|
| 71 |
fn=predict,
|
| 72 |
inputs=gr.Image(type="pil"),
|
| 73 |
outputs=[
|
|
@@ -80,5 +80,5 @@ demo = gr.Interface(
|
|
| 80 |
article=article,
|
| 81 |
)
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
|
|
|
|
| 1 |
+
### 1. Imports and class names setup
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import torch
|
|
|
|
| 8 |
from typing import Tuple, Dict
|
| 9 |
|
| 10 |
# Setup class names
|
| 11 |
+
with open("class_names.txt", "r") as f: # reading target labels from class_names.txt
|
| 12 |
class_names = [food_name.strip() for food_name in f.readlines()]
|
| 13 |
|
| 14 |
+
### 2. Model and transforms preparation
|
| 15 |
|
| 16 |
# Create model
|
| 17 |
effnetb2, effnetb2_transforms = create_effnetb2_model(
|
| 18 |
+
num_classes=len(class_names),
|
| 19 |
+
)
|
| 20 |
|
| 21 |
# Load saved weights
|
| 22 |
effnetb2.load_state_dict(
|
|
|
|
| 56 |
return pred_labels_and_probs, pred_time
|
| 57 |
|
| 58 |
|
| 59 |
+
### 4. Gradio app
|
| 60 |
|
| 61 |
+
# Create title, description and article
|
| 62 |
title = "FoodVision Big 🍔👁"
|
| 63 |
+
description = "A Simple Deep Learning Application which is trained on EfficientNetB2 Fine Tuned computer vision model to classify food images of [101 different classes](https://huggingface.co/spaces/Hexii/FoodVision/blob/main/class_names.txt)."
|
| 64 |
+
article = "Created by Ansari Abu Huzaifa , Learned at[ZTM Academy](https://www.learnpytorch.io/)"
|
| 65 |
|
| 66 |
# Create examples list from "examples/" directory
|
| 67 |
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
| 68 |
|
| 69 |
+
# Create Gradio interface
|
| 70 |
+
app = gr.Interface(
|
| 71 |
fn=predict,
|
| 72 |
inputs=gr.Image(type="pil"),
|
| 73 |
outputs=[
|
|
|
|
| 80 |
article=article,
|
| 81 |
)
|
| 82 |
|
| 83 |
+
# launch the App
|
| 84 |
+
app.launch()
|