eddydpan commited on
Commit
678e3b3
1 Parent(s): 9c1511a

output format + mode of disposal

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -5,14 +5,20 @@ import open_clip
5
 
6
  model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='laion2b_s34b_b79k')
7
  tokenizer = open_clip.get_tokenizer('ViT-B-32')
 
8
  material_list = []
 
9
 
10
  with open("results.txt", "r") as f:
11
  results = f.readlines()
12
  for line in results:
 
 
 
13
  material = line.split(" [")[0]
14
  material_list.append(material.strip()) # Trim any leading/trailing whitespace
15
  f.close()
 
16
  text = tokenizer(material_list)
17
 
18
  def process_image(image_input, material_input):
@@ -34,12 +40,13 @@ def process_image(image_input, material_input):
34
  for row in text_probs:
35
  for column in row:
36
  float_values.append(float(column))
37
- results[float(column)] = material_list[counter]
38
  counter += 1
39
 
40
  sorted_float_values = sorted(float_values, reverse=True)
41
  # print(sorted_float_values)
42
 
 
43
  index = -1
44
  for i in range(len(material_list)):
45
  if material_list[i] == material_input:
@@ -48,9 +55,13 @@ def process_image(image_input, material_input):
48
  if index == -1:
49
  material_accuracy = None
50
  else:
51
- material_accuracy = material_input + ": " + str(float_values[index])
 
 
 
 
 
52
 
53
- return [[results[sorted_float_values[0]], sorted_float_values[0]], [results[sorted_float_values[1]], sorted_float_values[1]], [results[sorted_float_values[2]], sorted_float_values[2]], material_accuracy]
54
 
55
  inputs = [gr.inputs.Image(type="pil"), gr.inputs.Dropdown(material_list)]
56
  outputs = [gr.outputs.Textbox(label="Top Result"), gr.outputs.Textbox(label="Second Result"), gr.outputs.Textbox(label="Third Result"), gr.outputs.Textbox(label="Material Accuracy")]
 
5
 
6
  model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='laion2b_s34b_b79k')
7
  tokenizer = open_clip.get_tokenizer('ViT-B-32')
8
+
9
  material_list = []
10
+ disposal_list = []
11
 
12
  with open("results.txt", "r") as f:
13
  results = f.readlines()
14
  for line in results:
15
+ disposal = line.split("\'")[1]
16
+ disposal_list.append(disposal.strip())
17
+
18
  material = line.split(" [")[0]
19
  material_list.append(material.strip()) # Trim any leading/trailing whitespace
20
  f.close()
21
+
22
  text = tokenizer(material_list)
23
 
24
  def process_image(image_input, material_input):
 
40
  for row in text_probs:
41
  for column in row:
42
  float_values.append(float(column))
43
+ results[float(column)] = [ material_list[counter], disposal_list[counter] ]
44
  counter += 1
45
 
46
  sorted_float_values = sorted(float_values, reverse=True)
47
  # print(sorted_float_values)
48
 
49
+
50
  index = -1
51
  for i in range(len(material_list)):
52
  if material_list[i] == material_input:
 
55
  if index == -1:
56
  material_accuracy = None
57
  else:
58
+ material_accuracy = disposal_list[index] + " - " + material_list[index] + ": " + str(float_values[index])
59
+ first = results[sorted_float_values[0]][1] + " - " + results[sorted_float_values[0]][0] + ": " + str(sorted_float_values[0])
60
+ second = results[sorted_float_values[1]][1] + " - " + results[sorted_float_values[1]][0] + ": " + str(sorted_float_values[1])
61
+ third = results[sorted_float_values[2]][1] + " - " + results[sorted_float_values[2]][0] + ": " + str(sorted_float_values[2])
62
+
63
+ return [first, second, third, material_accuracy]
64
 
 
65
 
66
  inputs = [gr.inputs.Image(type="pil"), gr.inputs.Dropdown(material_list)]
67
  outputs = [gr.outputs.Textbox(label="Top Result"), gr.outputs.Textbox(label="Second Result"), gr.outputs.Textbox(label="Third Result"), gr.outputs.Textbox(label="Material Accuracy")]