Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,37 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
st.set_page_config(page_title="Crop Disease Detection App")
|
39 |
-
|
40 |
-
st.header("Gemini Crop Disease App")
|
41 |
-
input=st.text_input("Input Prompt: ",key="input")
|
42 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
43 |
-
image=""
|
44 |
-
if uploaded_file is not None:
|
45 |
-
image = Image.open(uploaded_file)
|
46 |
-
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
47 |
-
|
48 |
-
|
49 |
-
submit=st.button("Predict Crop/Plant Health")
|
50 |
-
|
51 |
-
input_prompt="""
|
52 |
-
"You are an expert in computer vision and agriculture who can easily predict the disease of the plant. "
|
53 |
-
"Analyze the following image and provide 6 outputs in a structured table format: "
|
54 |
-
"1. Crop in the image, "
|
55 |
-
"2. Whether it is infected or healthy, "
|
56 |
-
"3. Type of disease (if any), "
|
57 |
-
"4. How confident out of 100% whether image is healthy or infected "
|
58 |
-
"5. Reason for the disease such as whether it is happening due to fungus, bacteria, insect bite, poor nutrition, etc., "
|
59 |
-
"6. Precautions for it."
|
60 |
-
"""
|
61 |
-
|
62 |
-
## If submit button is clicked
|
63 |
-
|
64 |
-
if submit:
|
65 |
-
image_data=input_image_setup(uploaded_file)
|
66 |
-
response=get_gemini_repsonse(input_prompt,image_data,input)
|
67 |
-
st.subheader("The Response is")
|
68 |
-
st.write(response)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from google.generativeai import generative_language_v1beta
|
3 |
+
|
4 |
+
# Initialize the model
|
5 |
+
model = generative_language_v1beta.GenerativeModel(model_name="gemini-1.5-flash")
|
6 |
+
|
7 |
+
def get_gemini_response(image_data):
|
8 |
+
input_prompt = "Analyze the uploaded plant image."
|
9 |
+
|
10 |
+
# Use the model to generate a response based on the uploaded image
|
11 |
+
response = model.generate_content([input_prompt, image_data])
|
12 |
+
|
13 |
+
# Process the response to extract relevant information
|
14 |
+
output = {
|
15 |
+
"Crop in the image": response.get("crop", "Unknown"), # Adjust based on actual response structure
|
16 |
+
"Whether it is infected or healthy": response.get("health_status", "Unknown"), # Actual response
|
17 |
+
"Type of disease (if any)": response.get("disease_type", "None"), # Actual response
|
18 |
+
"Confidence percentage": response.get("confidence", "N/A"), # Actual response
|
19 |
+
"Reason for the disease": response.get("reason", "Not specified"), # Actual response
|
20 |
+
"Precautions for it": response.get("precautions", "None provided") # Actual response
|
21 |
+
}
|
22 |
+
|
23 |
+
# Format the output
|
24 |
+
output_string = "The Response is:\n" + "\n".join([f"{key}: {value}" for key, value in output.items()])
|
25 |
+
return output_string
|
26 |
+
|
27 |
+
# Set up the Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=get_gemini_response,
|
30 |
+
inputs=gr.Image(type="pil"), # Accept image uploads
|
31 |
+
outputs="text", # Output text response
|
32 |
+
title="Plant Disease Diagnosis",
|
33 |
+
description="Upload a plant image to analyze its health status and identify any diseases."
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the Gradio application
|
37 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|