Raja commited on
Commit
ce8b148
1 Parent(s): c04ee86

Adding both checkbox

Browse files
Files changed (1) hide show
  1. app.py +71 -27
app.py CHANGED
@@ -62,7 +62,7 @@ def consolidate_score(thermal_result,rgb_result):
62
  return output_consol
63
  thermal_check = st.checkbox("Thermal Input")
64
  rgb_check = st.checkbox("RGB Input")
65
- thermal_execution,rgb_execution=False,False
66
  if(thermal_check or rgb_check):
67
  if(thermal_check):
68
 
@@ -82,35 +82,37 @@ if(thermal_check or rgb_check):
82
  pipe_thermal = create_pipeline(feature_extractor_thermal,model_thermal)
83
  # opencv_image = np.array(opencv_image)
84
  thermal_result=pipe_thermal(input_image)
85
- thermal_execution=True
 
 
 
 
 
 
 
 
 
 
 
 
86
  if(rgb_check):
87
 
88
- st.write("RGB Image file uploader...")
89
- uploaded_file = st.file_uploader("Choose a rgb image file", type=["jpg","png"])
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
- if uploaded_file is not None:
92
- input_image = Image.open(uploaded_file)
93
- st.write("Input Image...")
94
- st.image(input_image)
95
- dataset_thermal,dataset_rgb = load_dataset_from_Hugging_Face()
96
- labels=dataset_thermal["train"].features["label"].names
97
- id2label={k:v for k,v in enumerate(labels)}
98
- label2id = {v:k for k,v in enumerate(labels)}
99
- feature_extractor_rgb,model_rgb = load_model_from_Hugging_Face("rgb")
100
- pipe_rgb = create_pipeline(feature_extractor_rgb,model_rgb)
101
- rgb_result=pipe_rgb(input_image)
102
- rgb_execution=True
103
- if(not rgb_check):
104
- rgb_execution=True
105
- if(not thermal_check):
106
- thermal_execution=True
107
- if(thermal_check and rgb_check and thermal_execution and rgb_execution):
108
- consolidated_result=get_output_label(consolidate_score(thermal_result,rgb_result))
109
- elif(thermal_check and thermal_execution and not rgb_check):
110
- consolidated_result=get_output_label(thermal_result)
111
- elif(rgb_check and rgb_execution and not thermal_check):
112
  consolidated_result=get_output_label(rgb_result)
113
- if(thermal_execution and rgb_execution):
114
  if(consolidated_result!="RiceLeafs_Healthy"):
115
  f = open("remedy.json")
116
  data = json.load(f)
@@ -119,4 +121,46 @@ if(thermal_check or rgb_check):
119
  for key in i:
120
  st.write(key," : ",i[key])
121
  else:
122
- st.write(consolidated_result.split("_")[0]," is ",consolidated_result.split("_")[1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  return output_consol
63
  thermal_check = st.checkbox("Thermal Input")
64
  rgb_check = st.checkbox("RGB Input")
65
+ both_check = st.checkbox("Both")
66
  if(thermal_check or rgb_check):
67
  if(thermal_check):
68
 
 
82
  pipe_thermal = create_pipeline(feature_extractor_thermal,model_thermal)
83
  # opencv_image = np.array(opencv_image)
84
  thermal_result=pipe_thermal(input_image)
85
+
86
+
87
+ consolidated_result=get_output_label(thermal_result)
88
+ if(consolidated_result!="RiceLeafs_Healthy"):
89
+ f = open("remedy.json")
90
+ data = json.load(f)
91
+ for i in data[consolidated_result.split("_")[0]]:
92
+ if(i["disease_name"]==consolidated_result.split("_")[1]):
93
+ for key in i:
94
+ st.write(key," : ",i[key])
95
+ else:
96
+ st.write(consolidated_result.split("_")[0]," is ",consolidated_result.split("_")[1])
97
+
98
  if(rgb_check):
99
 
100
+ st.write("RGB Image file uploader...")
101
+ uploaded_file = st.file_uploader("Choose a rgb image file", type=["jpg","png"])
102
+
103
+ if uploaded_file is not None:
104
+ input_image = Image.open(uploaded_file)
105
+ st.write("Input Image...")
106
+ st.image(input_image)
107
+ dataset_thermal,dataset_rgb = load_dataset_from_Hugging_Face()
108
+ labels=dataset_thermal["train"].features["label"].names
109
+ id2label={k:v for k,v in enumerate(labels)}
110
+ label2id = {v:k for k,v in enumerate(labels)}
111
+ feature_extractor_rgb,model_rgb = load_model_from_Hugging_Face("rgb")
112
+ pipe_rgb = create_pipeline(feature_extractor_rgb,model_rgb)
113
+ rgb_result=pipe_rgb(input_image)
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  consolidated_result=get_output_label(rgb_result)
 
116
  if(consolidated_result!="RiceLeafs_Healthy"):
117
  f = open("remedy.json")
118
  data = json.load(f)
 
121
  for key in i:
122
  st.write(key," : ",i[key])
123
  else:
124
+ st.write(consolidated_result.split("_")[0]," is ",consolidated_result.split("_")[1])
125
+
126
+ if(both_check):
127
+ st.write("Thermal Image file uploader...")
128
+ uploaded_file = st.file_uploader("Choose a thermal image file", type=["jpg","png"])
129
+
130
+ if uploaded_file is not None:
131
+ input_image = Image.open(uploaded_file)
132
+ st.write("Input Image...")
133
+ st.image(input_image)
134
+ dataset_thermal,dataset_rgb = load_dataset_from_Hugging_Face()
135
+ labels=dataset_thermal["train"].features["label"].names
136
+ id2label={k:v for k,v in enumerate(labels)}
137
+ label2id = {v:k for k,v in enumerate(labels)}
138
+
139
+ feature_extractor_thermal,model_thermal = load_model_from_Hugging_Face("thermal")
140
+ pipe_thermal = create_pipeline(feature_extractor_thermal,model_thermal)
141
+ # opencv_image = np.array(opencv_image)
142
+ thermal_result=pipe_thermal(input_image)
143
+ st.write("RGB Image file uploader...")
144
+ uploaded_file = st.file_uploader("Choose a rgb image file", type=["jpg","png"])
145
+
146
+ if uploaded_file is not None:
147
+ input_image = Image.open(uploaded_file)
148
+ st.write("Input Image...")
149
+ st.image(input_image)
150
+ dataset_thermal,dataset_rgb = load_dataset_from_Hugging_Face()
151
+ labels=dataset_thermal["train"].features["label"].names
152
+ id2label={k:v for k,v in enumerate(labels)}
153
+ label2id = {v:k for k,v in enumerate(labels)}
154
+ feature_extractor_rgb,model_rgb = load_model_from_Hugging_Face("rgb")
155
+ pipe_rgb = create_pipeline(feature_extractor_rgb,model_rgb)
156
+ rgb_result=pipe_rgb(input_image)
157
+ consolidated_result=get_output_label(consolidate_score(thermal_result,rgb_result))
158
+ if(consolidated_result!="RiceLeafs_Healthy"):
159
+ f = open("remedy.json")
160
+ data = json.load(f)
161
+ for i in data[consolidated_result.split("_")[0]]:
162
+ if(i["disease_name"]==consolidated_result.split("_")[1]):
163
+ for key in i:
164
+ st.write(key," : ",i[key])
165
+ else:
166
+ st.write(consolidated_result.split("_")[0]," is ",consolidated_result.split("_")[1])