Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -55,14 +55,14 @@ def predict_disease(image):
|
|
55 |
# Get the predicted label
|
56 |
predicted_label = class_names[predicted_class.item()]
|
57 |
|
58 |
-
# Generate
|
59 |
prompt = f"The detected sugarcane disease is '{predicted_label}'. Provide detailed advice for managing this condition."
|
60 |
-
ai_response = ai_pipeline(prompt, max_length=
|
61 |
-
|
62 |
-
# Remove the prompt text if it appears in the AI response
|
63 |
-
if ai_response.startswith(prompt):
|
64 |
-
ai_response = ai_response[len(prompt):].strip()
|
65 |
|
|
|
|
|
|
|
|
|
66 |
# Create a styled HTML output
|
67 |
output_message = f"""
|
68 |
<div style='font-size: 18px; color: #4CAF50; font-weight: bold;'>
|
@@ -73,7 +73,7 @@ def predict_disease(image):
|
|
73 |
if predicted_label != "Healthy":
|
74 |
output_message += f"""
|
75 |
<p style='font-size: 16px; color: #757575;'>
|
76 |
-
|
77 |
</p>
|
78 |
"""
|
79 |
else:
|
|
|
55 |
# Get the predicted label
|
56 |
predicted_label = class_names[predicted_class.item()]
|
57 |
|
58 |
+
# Generate a detailed response for the detected disease
|
59 |
prompt = f"The detected sugarcane disease is '{predicted_label}'. Provide detailed advice for managing this condition."
|
60 |
+
ai_response = ai_pipeline(prompt, max_length=100, num_return_sequences=1, truncation=True)[0]['generated_text']
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
# Post-process the AI response to ensure it ends with a complete sentence
|
63 |
+
if not ai_response.endswith(('.', '!', '?')):
|
64 |
+
ai_response = ai_response.rsplit('.', 1)[0] + '.'
|
65 |
+
|
66 |
# Create a styled HTML output
|
67 |
output_message = f"""
|
68 |
<div style='font-size: 18px; color: #4CAF50; font-weight: bold;'>
|
|
|
73 |
if predicted_label != "Healthy":
|
74 |
output_message += f"""
|
75 |
<p style='font-size: 16px; color: #757575;'>
|
76 |
+
{ai_response}
|
77 |
</p>
|
78 |
"""
|
79 |
else:
|