sowbaranika13 commited on
Commit
3abe170
·
verified ·
1 Parent(s): 9a3a504

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  from tensorflow.keras.models import load_model
4
- from tensorflow.keras.preprocessing.image import img_to_array
5
  import numpy as np
6
  import os
7
- from huggingface_hub import hf_hub_download
8
 
9
- # Labels for class and species
10
  labels = {
11
  'class': ['amphibia', 'aves', 'invertebrates', 'lacertilia', 'mammalia', 'serpentes', 'testudines'],
12
  'serpentes': ["Butler's Gartersnake", "Dekay's Brownsnake", 'Eastern Gartersnake', 'Eastern Hog-nosed snake', 'Eastern Massasauga', 'Eastern Milksnake', 'Eastern Racer Snake', 'Eastern Ribbonsnake', 'Gray Ratsnake', "Kirtland's Snake", 'Northern Watersnake', 'Plains Gartersnake', 'Red-bellied Snake', 'Smooth Greensnake'],
@@ -15,16 +15,13 @@ labels = {
15
  'amphibia': ['American Bullfrog', 'American Toad', 'Green Frog', 'Northern Leopard Frog']
16
  }
17
 
18
- # Function to download the model from Hugging Face Hub
19
- def get_model_from_hub(repo_id, filename):
20
- model_path = hf_hub_download(repo_id=repo_id, filename=filename)
21
- return load_model(model_path)
22
-
23
- # Download and load the model
24
- hierarchical_models = {
25
- 'class': get_model_from_hub("sowbaranika13/inceptionv3_class", "inceptionv3_class.h5")
26
- }
27
 
 
 
 
 
 
28
  def load_and_preprocess_image(image, target_size=(299, 299)):
29
  img_array = img_to_array(image)
30
  img_array = np.expand_dims(img_array, axis=0)
@@ -46,7 +43,7 @@ def predict(image):
46
  species_idx = np.argmax(species_preds)
47
  species_label = labels[class_label][species_idx]
48
  results['species'] = species_label
49
-
50
  return results
51
 
52
  # Create Gradio interface
@@ -59,4 +56,4 @@ iface = gr.Interface(
59
  )
60
 
61
  # Launch the interface
62
- iface.launch()
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing.image import img_to_array, load_img
5
  import numpy as np
6
  import os
7
+ import requests
8
 
9
+ # Load your model and tokenizer
10
  labels = {
11
  'class': ['amphibia', 'aves', 'invertebrates', 'lacertilia', 'mammalia', 'serpentes', 'testudines'],
12
  'serpentes': ["Butler's Gartersnake", "Dekay's Brownsnake", 'Eastern Gartersnake', 'Eastern Hog-nosed snake', 'Eastern Massasauga', 'Eastern Milksnake', 'Eastern Racer Snake', 'Eastern Ribbonsnake', 'Gray Ratsnake', "Kirtland's Snake", 'Northern Watersnake', 'Plains Gartersnake', 'Red-bellied Snake', 'Smooth Greensnake'],
 
15
  'amphibia': ['American Bullfrog', 'American Toad', 'Green Frog', 'Northern Leopard Frog']
16
  }
17
 
18
+ hierarchical_models = {}
 
 
 
 
 
 
 
 
19
 
20
+ model_path = r"inceptionv3_class.h5"
21
+ print(model_path)
22
+ hierarchical_models['class'] = load_model(model_path)
23
+ print(hierarchical_models)
24
+
25
  def load_and_preprocess_image(image, target_size=(299, 299)):
26
  img_array = img_to_array(image)
27
  img_array = np.expand_dims(img_array, axis=0)
 
43
  species_idx = np.argmax(species_preds)
44
  species_label = labels[class_label][species_idx]
45
  results['species'] = species_label
46
+ print(results)
47
  return results
48
 
49
  # Create Gradio interface
 
56
  )
57
 
58
  # Launch the interface
59
+ iface.launch()