Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -836,9 +836,10 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
| 836 |
print("Error: Image data is not available.")
|
| 837 |
return None
|
| 838 |
|
| 839 |
-
if
|
| 840 |
-
|
| 841 |
-
|
|
|
|
| 842 |
|
| 843 |
image = cv.imdecode(np.frombuffer(image_data, np.uint8), cv.IMREAD_COLOR)
|
| 844 |
image = cv.resize(image, (224, 224))
|
|
@@ -884,7 +885,10 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
| 884 |
|
| 885 |
if max_rounded_prediction > 0.5:
|
| 886 |
print("\nWays to dispose of this waste: " + max_label)
|
| 887 |
-
|
|
|
|
|
|
|
|
|
|
| 888 |
print("IMAGE messages after appending:", messages)
|
| 889 |
|
| 890 |
print("Message list of image:", messages)
|
|
@@ -913,13 +917,18 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
| 913 |
# reply = response.choices[0].message['content']
|
| 914 |
print("RESPONSE TRY", completion)
|
| 915 |
|
| 916 |
-
|
| 917 |
-
|
|
|
|
|
|
|
| 918 |
except:
|
| 919 |
print("DOESN'T WORK")
|
| 920 |
|
| 921 |
elif max_rounded_prediction < 0.5:
|
| 922 |
-
|
|
|
|
|
|
|
|
|
|
| 923 |
|
| 924 |
return output
|
| 925 |
|
|
|
|
| 836 |
print("Error: Image data is not available.")
|
| 837 |
return None
|
| 838 |
|
| 839 |
+
if UserInput.lower() is not None:
|
| 840 |
+
caption = UserInput.lower()
|
| 841 |
+
else:
|
| 842 |
+
caption = ""
|
| 843 |
|
| 844 |
image = cv.imdecode(np.frombuffer(image_data, np.uint8), cv.IMREAD_COLOR)
|
| 845 |
image = cv.resize(image, (224, 224))
|
|
|
|
| 885 |
|
| 886 |
if max_rounded_prediction > 0.5:
|
| 887 |
print("\nWays to dispose of this waste: " + max_label)
|
| 888 |
+
if caption == None:
|
| 889 |
+
messages.append({"role": "user", "content": content + " " + max_label})
|
| 890 |
+
else:
|
| 891 |
+
messages.append({"role": "user", "content": caption})
|
| 892 |
print("IMAGE messages after appending:", messages)
|
| 893 |
|
| 894 |
print("Message list of image:", messages)
|
|
|
|
| 917 |
# reply = response.choices[0].message['content']
|
| 918 |
print("RESPONSE TRY", completion)
|
| 919 |
|
| 920 |
+
if caption == None:
|
| 921 |
+
output.append({"Mode": "Image", "type": max_label, "prediction_value": max_rounded_prediction, "content": reply})
|
| 922 |
+
else:
|
| 923 |
+
output.append({"Mode": "Image with Caption", "content": reply})
|
| 924 |
except:
|
| 925 |
print("DOESN'T WORK")
|
| 926 |
|
| 927 |
elif max_rounded_prediction < 0.5:
|
| 928 |
+
if caption == None:
|
| 929 |
+
output.append({"Mode": "Image", "type": "Not predictable", "prediction_value": max_rounded_prediction, "content": "Seems like the prediction rate is too low due to that won't be able to predict the type of material. Try again with a cropped image or different one"})
|
| 930 |
+
else:
|
| 931 |
+
pass
|
| 932 |
|
| 933 |
return output
|
| 934 |
|