SURESHBEEKHANI commited on
Commit
c613989
Β·
verified Β·
1 Parent(s): 247f8f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -23
app.py CHANGED
@@ -158,9 +158,6 @@ def generate_rice_report(image_data, img_format, client):
158
  st.error(f"API communication error: {str(e)}")
159
  return None
160
 
161
- # ======================
162
- # UI COMPONENTS
163
- # ======================
164
  def display_main_interface():
165
  """Render primary application interface"""
166
  st.title("🌾 Rice Quality Analyzer")
@@ -174,28 +171,17 @@ def render_sidebar(client):
174
  uploaded_file = st.file_uploader("Select an image or video", type=ALLOWED_FILE_TYPES + ALLOWED_VIDEO_TYPES)
175
 
176
  if uploaded_file:
177
- file_type = uploaded_file.type
178
- if "video" in file_type:
179
- frames = extract_video_frames(uploaded_file)
180
- if frames:
181
- st.image(frames[0], caption="Extracted Frame for Analysis", use_column_width=True)
182
- frame_img = Image.fromarray(cv2.cvtColor(frames[0], cv2.COLOR_BGR2RGB))
183
- buffer = io.BytesIO()
184
- frame_img.save(buffer, format="JPEG")
185
- base64_image = base64.b64encode(buffer.getvalue()).decode('utf-8')
186
- report = generate_rice_report(base64_image, "jpeg", client)
187
- else:
188
- st.image(Image.open(uploaded_file), caption="Uploaded Image", use_column_width=True)
189
- base64_image, img_format = process_image_data(uploaded_file)
190
- report = generate_rice_report(base64_image, img_format, client)
191
 
192
  if report:
193
- st.markdown("### πŸ“‹ Analysis Report")
194
- st.markdown(report)
 
 
 
 
195
 
196
- # ======================
197
- # APPLICATION ENTRYPOINT
198
- # ======================
199
  def main():
200
  configure_application()
201
  groq_client = initialize_api_client()
@@ -203,4 +189,4 @@ def main():
203
  render_sidebar(groq_client)
204
 
205
  if __name__ == "__main__":
206
- main()
 
158
  st.error(f"API communication error: {str(e)}")
159
  return None
160
 
 
 
 
161
  def display_main_interface():
162
  """Render primary application interface"""
163
  st.title("🌾 Rice Quality Analyzer")
 
171
  uploaded_file = st.file_uploader("Select an image or video", type=ALLOWED_FILE_TYPES + ALLOWED_VIDEO_TYPES)
172
 
173
  if uploaded_file:
174
+ base64_image, img_format = process_image_data(uploaded_file)
175
+ report = generate_rice_report(base64_image, img_format, client)
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  if report:
178
+ st.session_state.analysis_result = report
179
+ st.rerun()
180
+
181
+ if "analysis_result" in st.session_state:
182
+ st.markdown("### πŸ“‹ Analysis Report")
183
+ st.markdown(f'<div class="report-container"><div class="report-text">{st.session_state.analysis_result}</div></div>', unsafe_allow_html=True)
184
 
 
 
 
185
  def main():
186
  configure_application()
187
  groq_client = initialize_api_client()
 
189
  render_sidebar(groq_client)
190
 
191
  if __name__ == "__main__":
192
+ main()