Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ transformers.logging.set_verbosity_error()
|
|
24 |
|
25 |
|
26 |
|
27 |
-
def image_to_query(
|
28 |
"""
|
29 |
input: Image
|
30 |
|
@@ -32,10 +32,14 @@ def image_to_query(imagefile):
|
|
32 |
|
33 |
output: Query for the LLM
|
34 |
"""
|
35 |
-
|
36 |
-
classifier = pipeline("image-classification", model = "nprasad24/bean_classifier", from_tf = True)
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# Get the dictionary with the maximum score
|
41 |
max_score_dict = max(scores, key=lambda x: x['score'])
|
@@ -84,14 +88,14 @@ def ragChain():
|
|
84 |
[
|
85 |
(
|
86 |
"system",
|
87 |
-
"""You are a knowledgeable agricultural assistant. If a disease is detected, you have to give information on the disease.
|
|
|
88 |
If the plant is healthy, just give maintenance tips. """
|
89 |
),
|
90 |
(
|
91 |
"human",
|
92 |
"""Provide information about the leaf disease in question in bullet points.
|
93 |
Start your answer by mentioning the disease (if any) or healthy in this format: 'Condition: disease name'.
|
94 |
-
If the image is not of a plant, ask human to upload image of a plant and stop generating any response.
|
95 |
""",
|
96 |
),
|
97 |
|
@@ -127,7 +131,6 @@ def main(image):
|
|
127 |
query = image_to_query(image)
|
128 |
chain = ragChain()
|
129 |
output = generate_response(chain, query)
|
130 |
-
output = Markdown(output)
|
131 |
return output
|
132 |
|
133 |
title = "Bean Classifier and Instructor"
|
|
|
24 |
|
25 |
|
26 |
|
27 |
+
def image_to_query(image):
|
28 |
"""
|
29 |
input: Image
|
30 |
|
|
|
32 |
|
33 |
output: Query for the LLM
|
34 |
"""
|
35 |
+
image = Image.open(image)
|
|
|
36 |
|
37 |
+
model = AutoModelForImageClassification.from_pretrained("nprasad24/bean_classifier", from_tf=True)
|
38 |
+
image_processor = AutoImageProcessor.from_pretrained("nprasad24/bean_classifier")
|
39 |
+
|
40 |
+
classifier = pipeline("image-classification", model=model, image_processor=image_processor)
|
41 |
+
|
42 |
+
scores = classifier(image)
|
43 |
|
44 |
# Get the dictionary with the maximum score
|
45 |
max_score_dict = max(scores, key=lambda x: x['score'])
|
|
|
88 |
[
|
89 |
(
|
90 |
"system",
|
91 |
+
"""You are a knowledgeable agricultural assistant. If a disease is detected, you have to give information on the disease.
|
92 |
+
If the image is not of a plant, ask human to upload image of a plant and stop generating any response.
|
93 |
If the plant is healthy, just give maintenance tips. """
|
94 |
),
|
95 |
(
|
96 |
"human",
|
97 |
"""Provide information about the leaf disease in question in bullet points.
|
98 |
Start your answer by mentioning the disease (if any) or healthy in this format: 'Condition: disease name'.
|
|
|
99 |
""",
|
100 |
),
|
101 |
|
|
|
131 |
query = image_to_query(image)
|
132 |
chain = ragChain()
|
133 |
output = generate_response(chain, query)
|
|
|
134 |
return output
|
135 |
|
136 |
title = "Bean Classifier and Instructor"
|