Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -225,26 +225,30 @@ def classify(UserInput, Image, Textbox2, Textbox3):
|
|
225 |
|
226 |
if max_label_index is not None:
|
227 |
max_label = labels[max_label_index].split(' ', 1)[1]
|
228 |
-
|
|
|
229 |
|
230 |
time.sleep(1)
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
headers = {
|
235 |
-
"Content-Type": "application/json",
|
236 |
-
"Authorization": f"Bearer {auth}"
|
237 |
-
}
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
return output
|
250 |
|
|
|
225 |
|
226 |
if max_label_index is not None:
|
227 |
max_label = labels[max_label_index].split(' ', 1)[1]
|
228 |
+
rounded_prediction = round(max_prediction_value, 2)
|
229 |
+
print(f'Maximum Prediction: {max_label} with a value of {rounded_prediction}')
|
230 |
|
231 |
time.sleep(1)
|
232 |
+
if rounded_prediction > 0.5:
|
233 |
+
print("\nWays to dispose of this waste: " + max_label)
|
234 |
+
messages.append({"role": "user", "content": content + " " + max_label})
|
|
|
|
|
|
|
|
|
235 |
|
236 |
+
headers = {
|
237 |
+
"Content-Type": "application/json",
|
238 |
+
"Authorization": f"Bearer {auth}"
|
239 |
+
}
|
240 |
+
|
241 |
+
response = requests.post(host, headers=headers, json={
|
242 |
+
"messages": messages,
|
243 |
+
"model": model_llm
|
244 |
+
}).json()
|
245 |
+
|
246 |
+
reply = response["choices"][0]["message"]["content"]
|
247 |
+
messages.append({"role": "assistant", "content": reply})
|
248 |
+
|
249 |
+
output.append({"Mode": "Image", "type": max_label, "prediction_value": rounded_value, "content": reply})
|
250 |
+
elif rounded_prediction < 0.5:
|
251 |
+
output.append({"Mode": "Image", "type": "Not predictable", "prediction_value": rounded_value, "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."})
|
252 |
|
253 |
return output
|
254 |
|