tommy24 commited on
Commit
5db541e
·
1 Parent(s): 8c75ad7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -1,14 +1,9 @@
1
  import gradio as gr
2
- import tensorflow
3
  import numpy as np
4
  import cv2 as cv
5
  import requests
6
  import time
7
- import os
8
 
9
- host = os.environ.get("host")
10
- code = os.environ.get("code")
11
- model = os.environ.get("model")
12
  data = None
13
  model = None
14
  image = None
@@ -18,7 +13,6 @@ labels = None
18
  print('START')
19
  np.set_printoptions(suppress=True)
20
 
21
- model = tensorflow.keras.models.load_model('keras_model.h5')
22
  data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
23
 
24
  with open("labels.txt", "r") as file:
@@ -29,8 +23,13 @@ def classify(image_path):
29
  image_data = np.array(image_path)
30
  image_data = cv.resize(image_data, (224, 224))
31
  image_array = np.asarray(image_data)
32
- normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
33
  data[0] = normalized_image_array
 
 
 
 
 
34
  prediction = model.predict(data)
35
 
36
  max_label_index = None
@@ -52,15 +51,14 @@ def classify(image_path):
52
  print(f'Maximum Prediction: {max_label} with a value of {round(max_prediction_value, 2)}')
53
 
54
  time.sleep(1)
55
- print("\nWays to dispose this waste: " + max_label)
56
  payload = [
57
  {"role": "system", "content": "You are a helpful assistant."},
58
- {"role": "user", "content": "Give me the steps to dispose this waste in bulleting points 5 max: " + "Plastic"}
59
  ]
60
 
61
  response = requests.post(host, json={
62
  "messages": payload,
63
- "model": model,
64
  "temperature": 0.5,
65
  "presence_penalty": 0,
66
  "frequency_penalty": 0,
 
1
  import gradio as gr
 
2
  import numpy as np
3
  import cv2 as cv
4
  import requests
5
  import time
 
6
 
 
 
 
7
  data = None
8
  model = None
9
  image = None
 
13
  print('START')
14
  np.set_printoptions(suppress=True)
15
 
 
16
  data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
17
 
18
  with open("labels.txt", "r") as file:
 
23
  image_data = np.array(image_path)
24
  image_data = cv.resize(image_data, (224, 224))
25
  image_array = np.asarray(image_data)
26
+ normalized_image_array = (image_array.astype(np float32) / 127.0) - 1
27
  data[0] = normalized_image_array
28
+
29
+ # Load the model within the classify function
30
+ import tensorflow as tf
31
+ model = tf.keras.models.load_model('keras_model.h5')
32
+
33
  prediction = model.predict(data)
34
 
35
  max_label_index = None
 
51
  print(f'Maximum Prediction: {max_label} with a value of {round(max_prediction_value, 2)}')
52
 
53
  time.sleep(1)
54
+ print("\nWays to dispose of this waste: " + max_label)
55
  payload = [
56
  {"role": "system", "content": "You are a helpful assistant."},
57
+ {"role": "user", "content": "Give me the steps to dispose of this waste in bullet points (5 max): " + "Plastic"}
58
  ]
59
 
60
  response = requests.post(host, json={
61
  "messages": payload,
 
62
  "temperature": 0.5,
63
  "presence_penalty": 0,
64
  "frequency_penalty": 0,