Spaces:
Sleeping
Sleeping
added material list input dropdown and "Material Accuracy" output for the new input.
Browse files
app.py
CHANGED
@@ -13,10 +13,9 @@ with open("results.txt", "r") as f:
|
|
13 |
material = line.split(" [")[0]
|
14 |
material_list.append(material.strip()) # Trim any leading/trailing whitespace
|
15 |
f.close()
|
16 |
-
|
17 |
text = tokenizer(material_list)
|
18 |
|
19 |
-
def process_image(image_input):
|
20 |
|
21 |
results = {}
|
22 |
float_values = []
|
@@ -29,7 +28,7 @@ def process_image(image_input):
|
|
29 |
text_features /= text_features.norm(dim=-1, keepdim=True)
|
30 |
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
31 |
|
32 |
-
print("Label probs:", text_probs)
|
33 |
|
34 |
counter = 0
|
35 |
for row in text_probs:
|
@@ -39,11 +38,22 @@ def process_image(image_input):
|
|
39 |
counter += 1
|
40 |
|
41 |
sorted_float_values = sorted(float_values, reverse=True)
|
42 |
-
print(sorted_float_values)
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
interface = gr.Interface(fn=process_image, inputs=inputs, outputs=outputs)
|
49 |
interface.launch()
|
|
|
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):
|
19 |
|
20 |
results = {}
|
21 |
float_values = []
|
|
|
28 |
text_features /= text_features.norm(dim=-1, keepdim=True)
|
29 |
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
30 |
|
31 |
+
#print("Label probs:", text_probs)
|
32 |
|
33 |
counter = 0
|
34 |
for row in text_probs:
|
|
|
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:
|
46 |
+
index = i
|
47 |
+
break
|
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")]
|
57 |
|
58 |
interface = gr.Interface(fn=process_image, inputs=inputs, outputs=outputs)
|
59 |
interface.launch()
|