Hexii commited on
Commit
2442ab6
1 Parent(s): 1d06df8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
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 them in 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=101, # could also use len(class_names)
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 strings
62
  title = "FoodVision Big 🍔👁"
63
- description = "An EfficientNetB2 feature extractor computer vision model to classify images of food into [101 different classes](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/food101_class_names.txt)."
64
- article = "Created at [09. PyTorch Model Deployment](https://www.learnpytorch.io/09_pytorch_model_deployment/)."
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
- demo = gr.Interface(
71
  fn=predict,
72
  inputs=gr.Image(type="pil"),
73
  outputs=[
@@ -80,5 +80,5 @@ demo = gr.Interface(
80
  article=article,
81
  )
82
 
83
- # Launch the app!
84
- demo.launch(share=True)
 
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()