Row 6736

Row ID: 6736 | Dataset Entry | Axioma AXP Content Repository

Content Data

This page contains data entry 6736 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.

import streamlit as st import cv2 import numpy as np from tensorflow.keras.models import load_model import base64 from fpdf import FPDF # Load the trained model model = load_model("model.hdf5") # Dictionary mapping class numbers to class names class_names = {     0: "Plant: Apple\nDisease: Apple scab",     1: "Plant: Apple\nDisease: Black rot",     2: "Plant: Apple\nDisease: Cedar apple rust",     3: "Plant: Apple\nDisease: healthy",     4: "Plant: Blueberry\nDisease: healthy",     5: "Plant: Cherry (including sour)\nDisease: healthy",     6: "Plant: Cherry (including sour)\nDisease: Powdery mildew",     7: "Plant: Corn (maize)\nDisease: Cercospora leaf spot Gray leaf spot",     8: "Plant: Corn (maize)\nDisease: Common rust",     9: "Plant: Corn (maize)\nDisease: healthy",     10: "Plant: Corn (maize)\nDisease: Northern Leaf Blight",     11: "Plant: Grape\nDisease: Black rot",     12: "Plant: Grape\nDisease: Esca (Black Measles)",     13: "Plant: Grape\nDisease: healthy",     14: "Plant: Grape\nDisease: Leaf blight (Isariopsis Leaf Spot)",     15: "Plant: Orange\nDisease: Haunglongbing (Citrus greening)",     16: "Plant: Peach\nDisease: Bacterial spot",     17: "Plant: Peach\nDisease: healthy",     18: "Plant: Pepper\nDisease: bell Bacterial spot",     19: "Plant: Pepper\nDisease: bell healthy",     20: "Plant: Potato\nDisease: Early blight",     21: "Plant: Potato\nDisease: healthy",     22: "Plant: Potato\nDisease: Late blight",     23: "Plant: Raspberry\nDisease: healthy",     24: "Plant: Soybean\nDisease: healthy",     25: "Plant: Squash\nDisease: Powdery mildew",     26: "Plant: Strawberry\nDisease: healthy",     27: "Plant: Strawberry\nDisease: Leaf scorch",     28: "Plant: Tomato\nDisease: Bacterial spot",     29: "Plant: Tomato\nDisease: Early blight",     30: "Plant: Tomato\nDisease: healthy",     31: "Plant: Tomato\nDisease: Late blight",     32: "Plant: Tomato\nDisease: Leaf Mold",     33: "Plant: Tomato\nDisease: Septoria leaf spot",     34: "Plant: Tomato\nDisease: Spider mites Two-spotted spider mite",     35: "Plant: Tomato\nDisease: Target Spot",     36: "Plant: Tomato\nDisease: Tomato mosaic virus",     37: "Plant: Tomato\nDisease: Tomato Yellow Leaf Curl Virus" } # Function for preprocessing an uploaded image def preprocess_image(image):     img = cv2.resize(image, (224, 224))     img = img / 255.0  # Normalize pixel values     return img # Function to create a PDF report def create_pdf(image, predicted_class_name):     pdf = FPDF()     pdf.add_page()     pdf.set_font('Arial', 'B', 16)     pdf.cell(200, 10, txt="Plant Disease Detection Report", ln=True, align="C")     pdf.ln(10)     pdf.cell(200, 10, txt="Uploaded Image", ln=True, align="L")     pdf.ln(10)     # Convert the image to JPEG format and encode as base64     _, buffer = cv2.imencode('.jpg', image)     image_data = base64.b64encode(buffer).decode()     pdf.image('data:image/jpeg;base64,' + image_data, x=10, y=None, w=180)     pdf.ln(10)     pdf.cell(200, 10, txt="Prediction", ln=True, align="L")     pdf.ln(10)     pdf.multi_cell(0, 10, predicted_class_name)     return pdf # Streamlit app st.title("Plant Disease Detection") # File uploader widget uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) if uploaded_file is not None:     # Read the uploaded image     file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)     uploaded_image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)         # Display the uploaded image     st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)         # Add a button to trigger prediction     if st.button('Predict'):         # Preprocess the image         processed_image = preprocess_image(uploaded_image)                 # Make prediction         prediction = model.predict(np.expand_dims(processed_image, axis=0))         predicted_class = np.argmax(prediction)                 # Get the class name corresponding to the predicted class number         predicted_class_name = class_names.get(predicted_class, "Unknown")                 # Display the prediction         st.write(f"Predicted Class: {predicted_class_name}")                 # Add button to generate PDF report         export_as_pdf = st.button("Export Report")         if export_as_pdf:             # Create PDF report             pdf_report = create_pdf(uploaded_image, predicted_class_name)                         # Generate a download link for the PDF             pdf_bytes = pdf_report.output(dest="S").encode("latin-1")             b64 = base64.b64encode(pdf_bytes).decode()             href = f'<a href="data:application/octet-stream;base64,{b64}" download="plant_disease_report.pdf">Download Report</a>'             st.markdown(href, unsafe_allow_html=True)

FieldValue
text import streamlit as st import cv2 import numpy as np from tensorflow.keras.models import load_model import base64 from fpdf import FPDF # Load the trained model model = load_model("model.hdf5") # Dictionary mapping class numbers to class names class_names = {     0: "Plant: Apple\nDisease: Apple scab",     1: "Plant: Apple\nDisease: Black rot",     2: "Plant: Apple\nDisease: Cedar apple rust",     3: "Plant: Apple\nDisease: healthy", …
label r/deeplearning
dataType post
communityName r/deeplearning
datetime 2024-05-13
username_encoded Z0FBQUFBQm5LakwzeHdDZXRabDk0QTJWX0V2Q2MwTnZublFXNmpxUWNwdXBLeHlfTWhQNjlrTFFMSEhpaFljSUJNVXYtejVhdDZpWXdhQ3phaUt5SUdUOUtmQVE5YlJ6VU1lbFFVUFF0VWNyOWJHbW9qd0diYTA9
url_encoded Z0FBQUFBQm5Lak9Hb0VnYWtBNmpDSG55VFJVMk5sX25pdXVFOHBldEtOLWhfdEJTdXFMOVBlOFVxdjZySlpOdENmX0hwWmI4cURyV25wT0NuQXJPMGQtVzFDaVQ3UVFzRUx4WkFkVEtaMENVVnlTZTluRGZIbVB6T044amhLa3RNUHBIZVRJYXg1bmdzWDJ2ZjkzYWNjY0o4eDFDbE9EOTVCTExEMnROSnExM3ZpeUctc0xqYTBNNjFSODJ0ZDRDSmhVdTRZWmFfNXZz

Raw Record

{
  "text": "    import streamlit as st\n    import cv2\n    import numpy as np\n    from tensorflow.keras.models import load_model\n    import base64\n    from fpdf import FPDF\n    \n    # Load the trained model\n    model = load_model(\"model.hdf5\")\n    \n    # Dictionary mapping class numbers to class names\n    class_names = {\n        0: \"Plant: Apple\\nDisease: Apple scab\",\n        1: \"Plant: Apple\\nDisease: Black rot\",\n        2: \"Plant: Apple\\nDisease: Cedar apple rust\",\n        3: \"Plant: Apple\\nDisease: healthy\",\n        4: \"Plant: Blueberry\\nDisease: healthy\",\n        5: \"Plant: Cherry (including sour)\\nDisease: healthy\",\n        6: \"Plant: Cherry (including sour)\\nDisease: Powdery mildew\",\n        7: \"Plant: Corn (maize)\\nDisease: Cercospora leaf spot Gray leaf spot\",\n        8: \"Plant: Corn (maize)\\nDisease: Common rust\",\n        9: \"Plant: Corn (maize)\\nDisease: healthy\",\n        10: \"Plant: Corn (maize)\\nDisease: Northern Leaf Blight\",\n        11: \"Plant: Grape\\nDisease: Black rot\",\n        12: \"Plant: Grape\\nDisease: Esca (Black Measles)\",\n        13: \"Plant: Grape\\nDisease: healthy\",\n        14: \"Plant: Grape\\nDisease: Leaf blight (Isariopsis Leaf Spot)\",\n        15: \"Plant: Orange\\nDisease: Haunglongbing (Citrus greening)\",\n        16: \"Plant: Peach\\nDisease: Bacterial spot\",\n        17: \"Plant: Peach\\nDisease: healthy\",\n        18: \"Plant: Pepper\\nDisease: bell Bacterial spot\",\n        19: \"Plant: Pepper\\nDisease: bell healthy\",\n        20: \"Plant: Potato\\nDisease: Early blight\",\n        21: \"Plant: Potato\\nDisease: healthy\",\n        22: \"Plant: Potato\\nDisease: Late blight\",\n        23: \"Plant: Raspberry\\nDisease: healthy\",\n        24: \"Plant: Soybean\\nDisease: healthy\",\n        25: \"Plant: Squash\\nDisease: Powdery mildew\",\n        26: \"Plant: Strawberry\\nDisease: healthy\",\n        27: \"Plant: Strawberry\\nDisease: Leaf scorch\",\n        28: \"Plant: Tomato\\nDisease: Bacterial spot\",\n        29: \"Plant: Tomato\\nDisease: Early blight\",\n        30: \"Plant: Tomato\\nDisease: healthy\",\n        31: \"Plant: Tomato\\nDisease: Late blight\",\n        32: \"Plant: Tomato\\nDisease: Leaf Mold\",\n        33: \"Plant: Tomato\\nDisease: Septoria leaf spot\",\n        34: \"Plant: Tomato\\nDisease: Spider mites Two-spotted spider mite\",\n        35: \"Plant: Tomato\\nDisease: Target Spot\",\n        36: \"Plant: Tomato\\nDisease: Tomato mosaic virus\",\n        37: \"Plant: Tomato\\nDisease: Tomato Yellow Leaf Curl Virus\"\n    }\n    \n    # Function for preprocessing an uploaded image\n    def preprocess_image(image):\n        img = cv2.resize(image, (224, 224))\n        img = img / 255.0  # Normalize pixel values\n        return img\n    \n    # Function to create a PDF report\n    def create_pdf(image, predicted_class_name):\n        pdf = FPDF()\n        pdf.add_page()\n        pdf.set_font('Arial', 'B', 16)\n        pdf.cell(200, 10, txt=\"Plant Disease Detection Report\", ln=True, align=\"C\")\n        pdf.ln(10)\n        pdf.cell(200, 10, txt=\"Uploaded Image\", ln=True, align=\"L\")\n        pdf.ln(10)\n        # Convert the image to JPEG format and encode as base64\n        _, buffer = cv2.imencode('.jpg', image)\n        image_data = base64.b64encode(buffer).decode()\n        pdf.image('data:image/jpeg;base64,' + image_data, x=10, y=None, w=180)\n        pdf.ln(10)\n        pdf.cell(200, 10, txt=\"Prediction\", ln=True, align=\"L\")\n        pdf.ln(10)\n        pdf.multi_cell(0, 10, predicted_class_name)\n        return pdf\n    \n    # Streamlit app\n    st.title(\"Plant Disease Detection\")\n    \n    # File uploader widget\n    uploaded_file = st.file_uploader(\"Upload an image\", type=[\"jpg\", \"jpeg\", \"png\"])\n    \n    if uploaded_file is not None:\n        # Read the uploaded image\n        file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)\n        uploaded_image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)\n        \n        # Display the uploaded image\n        st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)\n        \n        # Add a button to trigger prediction\n        if st.button('Predict'):\n            # Preprocess the image\n            processed_image = preprocess_image(uploaded_image)\n            \n            # Make prediction\n            prediction = model.predict(np.expand_dims(processed_image, axis=0))\n            predicted_class = np.argmax(prediction)\n            \n            # Get the class name corresponding to the predicted class number\n            predicted_class_name = class_names.get(predicted_class, \"Unknown\")\n            \n            # Display the prediction\n            st.write(f\"Predicted Class: {predicted_class_name}\")\n            \n            # Add button to generate PDF report\n            export_as_pdf = st.button(\"Export Report\")\n            if export_as_pdf:\n                # Create PDF report\n                pdf_report = create_pdf(uploaded_image, predicted_class_name)\n                \n                # Generate a download link for the PDF\n                pdf_bytes = pdf_report.output(dest=\"S\").encode(\"latin-1\")\n                b64 = base64.b64encode(pdf_bytes).decode()\n                href = f'<a href=\"data:application/octet-stream;base64,{b64}\" download=\"plant_disease_report.pdf\">Download Report</a>'\n                st.markdown(href, unsafe_allow_html=True)\n    \n    ",
  "label": "r/deeplearning",
  "dataType": "post",
  "communityName": "r/deeplearning",
  "datetime": "2024-05-13",
  "username_encoded": "Z0FBQUFBQm5LakwzeHdDZXRabDk0QTJWX0V2Q2MwTnZublFXNmpxUWNwdXBLeHlfTWhQNjlrTFFMSEhpaFljSUJNVXYtejVhdDZpWXdhQ3phaUt5SUdUOUtmQVE5YlJ6VU1lbFFVUFF0VWNyOWJHbW9qd0diYTA9",
  "url_encoded": "Z0FBQUFBQm5Lak9Hb0VnYWtBNmpDSG55VFJVMk5sX25pdXVFOHBldEtOLWhfdEJTdXFMOVBlOFVxdjZySlpOdENmX0hwWmI4cURyV25wT0NuQXJPMGQtVzFDaVQ3UVFzRUx4WkFkVEtaMENVVnlTZTluRGZIbVB6T044amhLa3RNUHBIZVRJYXg1bmdzWDJ2ZjkzYWNjY0o4eDFDbE9EOTVCTExEMnROSnExM3ZpeUctc0xqYTBNNjFSODJ0ZDRDSmhVdTRZWmFfNXZz"
}

Entry Information