└── AgroDesktop ├── eb1.JPG ├── eb2.JPG ├── eb3.JPG ├── eb4.JPG ├── eb5.JPG ├── eb6.JPG ├── eb7.JPG ├── eb8.JPG ├── eb9.JPG ├── h5.JPG ├── h8.JPG ├── lb1.JPG ├── lb2.JPG ├── lb3.JPG ├── lb4.JPG ├── lb5.JPG ├── eb10.JPG ├── testx.hdf5 ├── image ├── icon.png ├── logo.png ├── test.png ├── layer4.png ├── login.png ├── loginX.png ├── search.png ├── close_eye.png ├── open_eye.png ├── back_button.png ├── uploadPhoto.png └── barchart01.py ├── __pycache__ ├── testZ.cpython-39.pyc ├── dash01.cpython-39.pyc ├── ml_module.cpython-39.pyc └── dbConnection.cpython-39.pyc ├── test02.py ├── test01.py ├── ml_module.py ├── testZ.py ├── ML.py ├── piechart01.py ├── dbConnection.py ├── login.py ├── dash02.py └── dash01.py /AgroDesktop/eb1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb1.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb2.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb3.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb4.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb5.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb6.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb6.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb7.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb7.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb8.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb8.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb9.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb9.JPG -------------------------------------------------------------------------------- /AgroDesktop/h5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/h5.JPG -------------------------------------------------------------------------------- /AgroDesktop/h8.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/h8.JPG -------------------------------------------------------------------------------- /AgroDesktop/lb1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/lb1.JPG -------------------------------------------------------------------------------- /AgroDesktop/lb2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/lb2.JPG -------------------------------------------------------------------------------- /AgroDesktop/lb3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/lb3.JPG -------------------------------------------------------------------------------- /AgroDesktop/lb4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/lb4.JPG -------------------------------------------------------------------------------- /AgroDesktop/lb5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/lb5.JPG -------------------------------------------------------------------------------- /AgroDesktop/eb10.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/eb10.JPG -------------------------------------------------------------------------------- /AgroDesktop/testx.hdf5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/testx.hdf5 -------------------------------------------------------------------------------- /AgroDesktop/image/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/icon.png -------------------------------------------------------------------------------- /AgroDesktop/image/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/logo.png -------------------------------------------------------------------------------- /AgroDesktop/image/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/test.png -------------------------------------------------------------------------------- /AgroDesktop/image/layer4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/layer4.png -------------------------------------------------------------------------------- /AgroDesktop/image/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/login.png -------------------------------------------------------------------------------- /AgroDesktop/image/loginX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/loginX.png -------------------------------------------------------------------------------- /AgroDesktop/image/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/search.png -------------------------------------------------------------------------------- /AgroDesktop/image/close_eye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/close_eye.png -------------------------------------------------------------------------------- /AgroDesktop/image/open_eye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/open_eye.png -------------------------------------------------------------------------------- /AgroDesktop/image/back_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/back_button.png -------------------------------------------------------------------------------- /AgroDesktop/image/uploadPhoto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/image/uploadPhoto.png -------------------------------------------------------------------------------- /AgroDesktop/__pycache__/testZ.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/__pycache__/testZ.cpython-39.pyc -------------------------------------------------------------------------------- /AgroDesktop/__pycache__/dash01.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/__pycache__/dash01.cpython-39.pyc -------------------------------------------------------------------------------- /AgroDesktop/__pycache__/ml_module.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/__pycache__/ml_module.cpython-39.pyc -------------------------------------------------------------------------------- /AgroDesktop/__pycache__/dbConnection.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PasinduWaidyarathna/Tomato-Disease-Detection/HEAD/AgroDesktop/__pycache__/dbConnection.cpython-39.pyc -------------------------------------------------------------------------------- /AgroDesktop/test02.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | # Data 4 | categories = ['Quality Tomato', 'Leaves Diseases', 'Insect Damage', 'Not Recognized'] 5 | percentages = [40, 12, 5, 10] 6 | colors = ['#32a85c', '#dde810', '#d61d09', '#bf9571'] 7 | 8 | # Plotting the bar chart 9 | plt.bar(categories, percentages, color=colors) 10 | 11 | # Adding labels and title 12 | #plt.xlabel('Categories') 13 | plt.ylabel('Percentage (%)') 14 | plt.title('Summary') 15 | 16 | # Display the chart 17 | plt.show() 18 | -------------------------------------------------------------------------------- /AgroDesktop/test01.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | # Data 4 | labels = ['Safe Tomato', 'Unsafe Tomato'] 5 | sizes = [82, 10] 6 | colors = ['#32a85c', '#dde810'] # Light Green for Safe, Light Yellow for Unsafe 7 | 8 | # Plotting the pie chart 9 | fig, ax = plt.subplots() 10 | ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, colors=colors) 11 | 12 | # Draw a white circle in the center to create a doughnut chart 13 | centre_circle = plt.Circle((0,0),0.70,fc='white') 14 | fig = plt.gcf() 15 | fig.gca().add_artist(centre_circle) 16 | 17 | # Equal aspect ratio ensures that pie is drawn as a circle. 18 | ax.axis('equal') 19 | 20 | plt.title('Scanned Tomato Percentage') 21 | 22 | # Display the chart 23 | plt.show() 24 | -------------------------------------------------------------------------------- /AgroDesktop/ml_module.py: -------------------------------------------------------------------------------- 1 | # ml_module.py 2 | 3 | import numpy as np 4 | import tensorflow as tf 5 | from keras.preprocessing import image 6 | from keras.applications.resnet50 import preprocess_input 7 | 8 | class MLModel: 9 | def __init__(self, model_path='testx.hdf5', class_names=None): 10 | self.model = tf.keras.models.load_model(model_path) 11 | self.class_names = class_names or ["Potato___Early_blight", "Potato___Late_blight", "Potato___healthy"] 12 | 13 | def predict_image(self, img_array): 14 | predictions = self.model.predict(img_array) 15 | predicted_class = np.argmax(predictions) 16 | predicted_probability = predictions[0, predicted_class] 17 | 18 | return self.class_names[predicted_class], predicted_probability * 100 19 | -------------------------------------------------------------------------------- /AgroDesktop/testZ.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | mydb = mysql.connector.connect(host="localhost", 6 | user="root", 7 | password="your password", 8 | database="database name") 9 | mycursor = mydb.cursor() 10 | 11 | # Fetching Data From mysql to my python program 12 | mycursor.execute("select Name, Marks from student_marks") 13 | result = mycursor.fetchall 14 | 15 | Names = [] 16 | Marks = [] 17 | 18 | for i in mycursor: 19 | Names.append(i[0]) 20 | Marks.append(i[1]) 21 | 22 | """print("Name of Students = ", Names) 23 | print("Marks of Students = ", Marks)""" 24 | #bar_color = 'skyblue' 25 | # Visualizing Data using Matplotlib 26 | num_students = len(Names) 27 | colors = np.random.rand(num_students, 3) 28 | plt.bar(Names, Marks,color=colors) 29 | plt.ylim(0, 100) 30 | plt.xlabel("Name of Students") 31 | plt.ylabel("Marks of Students") 32 | plt.title("Student's Information") 33 | plt.show() 34 | -------------------------------------------------------------------------------- /AgroDesktop/ML.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import tensorflow as tf 3 | from keras.preprocessing import image 4 | from keras.applications.resnet50 import preprocess_input 5 | 6 | model = tf.keras.models.load_model('testx.hdf5') 7 | 8 | # Load and preprocess the image 9 | img_path = 'lb5.jpg' 10 | img = image.load_img(img_path, target_size=(256, 256)) 11 | img_array = image.img_to_array(img) 12 | img_array = preprocess_input(img_array) 13 | img_array = np.expand_dims(img_array, axis=0) # Add batch dimension 14 | 15 | # Make prediction 16 | predictions = model.predict(img_array) 17 | 18 | # Get predicted class index 19 | predicted_class = np.argmax(predictions) 20 | 21 | # Assuming you have a list of class names 22 | class_names = ["Potato___Early_blight","Potato___Late_blight","Potato___healthy"] 23 | predicted_probability = predictions[0, predicted_class] 24 | # Print predicted class name and percentage 25 | print(f"Predicted class: {class_names[predicted_class]}") 26 | print(f"Predicted probability: {predicted_probability * 100:.2f}%") 27 | 28 | 29 | #print(f"Predicted class index: {predicted_class}") -------------------------------------------------------------------------------- /AgroDesktop/piechart01.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 3 | import matplotlib.pyplot as plt 4 | import tkinter as tk 5 | 6 | my_dict = {'NAME': ['Infant', 'Child', 'Young', 'Old'], 'Nos': [30, 40, 50, 50]} 7 | df = pd.DataFrame(data=my_dict) 8 | lbl = ['Infant', 'Child', 'Young', 'Old'] 9 | fig1 = df.plot.pie(title="Population", y='Nos', figsize=(3, 3), labels=lbl).get_figure() 10 | 11 | my_w = tk.Tk() 12 | my_w.geometry("1200x700") # Size of the window 13 | my_w.title('www.plus2net.com') 14 | 15 | # Get the width and height of the Tkinter window 16 | window_width = my_w.winfo_reqwidth() 17 | window_height = my_w.winfo_reqheight() 18 | 19 | # Calculate the position for the bottom-left corner 20 | x_position = 10 # You can adjust this value based on your preferences 21 | y_position = window_height - 10 - 3 * 80 # Adjusted to leave some space from the bottom 22 | 23 | # Place the pie chart using absolute coordinates 24 | plot1 = FigureCanvasTkAgg(fig1, master=my_w) 25 | plot1.get_tk_widget().place(x=x_position, y=y_position) 26 | 27 | my_w.mainloop() 28 | -------------------------------------------------------------------------------- /AgroDesktop/dbConnection.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | import dbConnection as db 3 | def connect_to_mysql(): 4 | # Replace the following with your MySQL database information 5 | host = 'localhost' 6 | user = 'root' 7 | password = 'your password' 8 | database = 'database name' 9 | 10 | try: 11 | # Create a connection to the MySQL server 12 | connection = mysql.connector.connect( 13 | host=host, 14 | user=user, 15 | password=password, 16 | database=database 17 | ) 18 | 19 | if connection.is_connected(): 20 | print(f"Connected to MySQL database '{database}'") 21 | 22 | # Perform database operations here 23 | 24 | except mysql.connector.Error as e: 25 | print(f"Error: {e}") 26 | 27 | finally: 28 | # Close the connection in the finally block 29 | if 'connection' in locals() and connection.is_connected(): 30 | connection.close() 31 | print("Connection closed") 32 | 33 | # Call the function to connect to MySQL 34 | connect_to_mysql() 35 | -------------------------------------------------------------------------------- /AgroDesktop/image/barchart01.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 5 | import tkinter as tk 6 | from matplotlib.figure import Figure 7 | 8 | # Function to generate the bar chart 9 | def generate_bar_chart(): 10 | mydb = mysql.connector.connect(host="localhost", 11 | user="root", 12 | password="Pradeepa64@", 13 | database="agro") 14 | mycursor = mydb.cursor() 15 | 16 | # Fetching Data From MySQL to my Python program 17 | mycursor.execute("SELECT Name, Marks FROM student_marks") 18 | result = mycursor.fetchall() 19 | 20 | Names = [] 21 | Marks = [] 22 | 23 | for i in result: 24 | Names.append(i[0]) 25 | Marks.append(i[1]) 26 | 27 | print("Name of Students = ", Names) 28 | print("Marks of Students = ", Marks) 29 | 30 | # Generating random colors for each student 31 | num_students = len(Names) 32 | colors = np.random.rand(num_students, 3) 33 | 34 | # Create the bar chart 35 | fig = Figure(figsize=(300/80, 200/80), dpi=80) 36 | ax = fig.add_subplot(111) 37 | bars = ax.bar(Names, Marks, color=colors) 38 | ax.set_ylim(0, 100) 39 | ax.set_xlabel("Name of Students") 40 | ax.set_ylabel("Marks of Students") 41 | ax.set_title("Student's Information") 42 | 43 | # Add the bar chart to the Tkinter window 44 | canvas = FigureCanvasTkAgg(fig, master=main_frame) 45 | canvas_widget = canvas.get_tk_widget() 46 | canvas_widget.pack(side=tk.TOP, fill=tk.BOTH, expand=1) 47 | 48 | # Draw the canvas 49 | canvas.draw() 50 | 51 | # Add the closing event for the Matplotlib figure 52 | canvas_widget.get_tk_widget().bind("", lambda e: plt.close(fig)) 53 | 54 | # Create the main Tkinter window 55 | main_window = tk.Tk() 56 | main_window.title("Student Information App") 57 | main_window.geometry("1200x720") 58 | 59 | # Create a frame for the bar chart 60 | main_frame = tk.Frame(main_window, width=300, height=200) 61 | main_frame.pack(side=tk.LEFT, padx=20, pady=20) 62 | 63 | # Button to generate the bar chart 64 | generate_button = tk.Button(main_window, text="Generate Bar Chart", command=generate_bar_chart) 65 | generate_button.pack(side=tk.TOP, pady=20) 66 | 67 | # Run the Tkinter event loop 68 | main_window.mainloop() 69 | -------------------------------------------------------------------------------- /AgroDesktop/login.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import messagebox 3 | import mysql.connector 4 | 5 | 6 | background = "#062883" 7 | framebg = "#EDEDED" 8 | framefg = "#06283D" 9 | 10 | 11 | global trial_no 12 | trial_no=0 13 | def trial(): 14 | global trial_no 15 | 16 | trial_no +=1 17 | if trial_no==3: 18 | messagebox.showwarning("Warning","You have tried more then limit!") 19 | root.destroy() #programclose 20 | 21 | def loginuser(): 22 | username=user.get() 23 | password=code.get() 24 | 25 | if(username=="" or username=="UserID") or (password=="" or password=="Password"): 26 | messagebox.showerror("Entry error","Type username or password!") 27 | 28 | else: 29 | try: 30 | 31 | mydb=mysql.connector.connect(host='localhost',user='root',password='your password',database="database name") 32 | mycursor=mydb.cursor() 33 | print("Connected to Database") 34 | 35 | except: 36 | messagebox.showerror("Connection","Database connection not stablish!") 37 | return 38 | 39 | command="use agro" 40 | mycursor.execute(command) 41 | 42 | command="select * from login where Username=%s and Password=%s" 43 | mycursor.execute(command,(username,password)) 44 | myresult=mycursor.fetchone() 45 | print(myresult) 46 | 47 | if myresult==None: 48 | 49 | messagebox.showinfo("Invalid","Invalid userid and password!") 50 | 51 | trial() 52 | 53 | else: 54 | messagebox.showinfo("Login","Sucessfully Login!") 55 | 56 | root.destroy() 57 | import dash01 58 | 59 | 60 | root = Tk() 61 | root.title("AGRODIAGNOBOT System") 62 | root.geometry("1250x700+210+100") 63 | root.config(bg=background) 64 | root.resizable(False, False) 65 | 66 | #icon image 67 | image_icon=PhotoImage(file="image/icon.png") 68 | root.iconphoto(False,image_icon) 69 | 70 | #background image 71 | frame=Frame(root,bg="red") 72 | frame.pack(fill=Y) 73 | 74 | backgroundimage=PhotoImage(file="image/login.png") 75 | Label(frame,image=backgroundimage).pack() 76 | 77 | #####user entry 78 | 79 | def user_enter(e): 80 | user.delete(0,'end') 81 | 82 | def user_leave(e): 83 | name=user.get() 84 | if name=='': 85 | user.insert(0,'UserID') 86 | 87 | user=Entry(frame,width=18,fg="#fff",border=0,bg="#375174",font=('Arial Bold',24)) 88 | user.insert(0,'UserID') 89 | user.bind("",user_enter) 90 | user.bind("",user_leave) 91 | user.place(x=500,y=315) 92 | 93 | #####password entry 94 | 95 | def password_enter(e): 96 | code.delete(0,'end') 97 | 98 | def password_leave(e): 99 | if code.get()=='': 100 | code.insert(0,'Password') 101 | 102 | code=Entry(frame,width=18,fg="#fff",border=0,bg="#375174",font=('Arial Bold',24)) 103 | code.insert(0,'Password') 104 | code.bind("",password_enter) 105 | code.bind("",password_leave) 106 | code.place(x=500,y=410) 107 | 108 | ####hide and show button 109 | button_mode=True 110 | 111 | def hide(): 112 | global button_mode 113 | 114 | if button_mode: 115 | eyeButton.config(image=closeeye, activebackground="white") 116 | code.config(show="*") 117 | button_mode = False 118 | else: 119 | eyeButton.config(image=openeye, activebackground="white") 120 | code.config(show="") 121 | button_mode = True 122 | 123 | openeye=PhotoImage(file="image/open_eye.png") 124 | closeeye=PhotoImage(file="image/close_eye.png") 125 | eyeButton=Button(frame,image=openeye,bg="#375174",bd=0,command=hide) 126 | eyeButton.place(x=780,y=410) 127 | 128 | ############## 129 | loginButton=Button(root,text="Login",bg="#1f5675",width=10,height=1,font=('arial',16,'bold'),bd=0,command=loginuser) 130 | loginButton.place(x=570,y=600) 131 | 132 | label=Label(root,text="Don't have an account?",fg="#fff",bg="#00264d",font=('Microsoft YaHei UI Light',9)) 133 | label.place(x=500,y=500) 134 | 135 | registerButton=Button(root,width=10,text="add new user",border=0,bg="#00264d",cursor='hand2',fg="#57a1f8") 136 | registerButton.place(x=650,y=500) 137 | 138 | 139 | 140 | root.mainloop() 141 | 142 | 143 | -------------------------------------------------------------------------------- /AgroDesktop/dash02.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import PhotoImage 3 | import mysql.connector 4 | import cv2 5 | from PIL import Image, ImageTk 6 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 7 | from matplotlib.figure import Figure 8 | import numpy as np 9 | import matplotlib.pyplot as plt 10 | import pandas as pd 11 | 12 | root = tk.Tk() 13 | root.title("AGRODIAGNOBOT System") 14 | root.geometry("1250x700+210+100") 15 | 16 | # Icon image 17 | image_icon = PhotoImage(file="image/icon.png") 18 | root.iconphoto(False, image_icon) 19 | 20 | camera_label = None 21 | 22 | 23 | def home_page(): 24 | global camera_label 25 | home_frame = tk.Frame(main_frame) 26 | 27 | lb = tk.Label(home_frame, text='Home Page : Camera Output ', font=('Bold', 15)) 28 | lb.pack() 29 | 30 | cap = cv2.VideoCapture(0) 31 | camera_label = tk.Label(home_frame) 32 | 33 | def update_camera(): 34 | ret, frame = cap.read() 35 | if ret: 36 | frame = cv2.resize(frame, (360, 250)) 37 | img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 38 | img = Image.fromarray(img) 39 | img = ImageTk.PhotoImage(img) 40 | camera_label.config(image=img) 41 | camera_label.image = img 42 | root.after(10, update_camera) 43 | 44 | camera_label = tk.Label(home_frame) 45 | camera_label.pack() 46 | update_camera() 47 | 48 | prediction_class_lb = tk.Label(home_frame, text='Prediction Class name : late-blight ') 49 | prediction_class_lb.pack() 50 | percentage_class_lb = tk.Label(home_frame, text='Percentage : 96.46% ') 51 | percentage_class_lb.pack() 52 | 53 | mydb = mysql.connector.connect(host="localhost", user="root", password="your password", database="database name") 54 | mycursor = mydb.cursor() 55 | # mycursor.execute("select Name, Marks from student_marks") 56 | mycursor.execute("select category,value from summary ORDER BY category DESC;") 57 | result = mycursor.fetchall() 58 | 59 | category = [] 60 | value = [] 61 | 62 | for i in result: 63 | category.append(i[0]) 64 | value.append(i[1]) 65 | 66 | # Initialize DataFrame for the pie chart 67 | df = pd.DataFrame(data={'NAME': ['Day 01', 'Day 02', 'Day 03', 'Day 04'], 'Nos': [30, 40, 50, 50]}) 68 | 69 | # Create a single figure for both bar chart and pie chart 70 | fig = plt.Figure(figsize=(15, 5)) 71 | 72 | # Subplot for the bar chart 73 | ax_bar = fig.add_subplot(121) 74 | #colors = ['green', 'brown', 'yellow', 'red'] 75 | rgb_values = [ 76 | (50, 168, 92), # Green 77 | (191, 149, 113), # Brown 78 | (221, 232, 16), # Yellow 79 | (214, 29, 9) # Red 80 | ] 81 | 82 | colors = [(r / 255, g / 255, b / 255) for r, g, b in rgb_values] 83 | #colors = np.random.rand(len(category), 3) 84 | category2 = ('Healthy\nTomato','Not\nRecognized','Leaves\nDiseases','Insect\nDamage') 85 | ax_bar.bar(category2,value, color=colors) 86 | ax_bar.set_ylim(0,50) 87 | ax_bar.set_xlabel("Category") 88 | ax_bar.set_ylabel("Percentage (%)") 89 | ax_bar.set_title("Summary") 90 | 91 | # Subplot for the pie chart 92 | ax_pie = fig.add_subplot(122) 93 | ax_pie.pie(df['Nos'], labels=df['NAME'], autopct='%1.1f%%', startangle=90) 94 | ax_pie.axis('equal') 95 | 96 | # Embed the single figure in Tkinter 97 | canvas = FigureCanvasTkAgg(fig, master=home_frame) 98 | canvas_widget = canvas.get_tk_widget() 99 | canvas_widget.pack() 100 | 101 | home_frame.pack(padx=20) 102 | 103 | 104 | 105 | def menu_page(): 106 | menu_frame = tk.Frame(main_frame) 107 | lb = tk.Label(menu_frame, text='Menu Page\n\nPage:2', font=('Bold', 30)) 108 | lb.pack() 109 | menu_frame.pack(padx=20) 110 | 111 | 112 | def contact_page(): 113 | contact_frame = tk.Frame(main_frame) 114 | lb = tk.Label(contact_frame, text='Contact Page\n\nPage:3', font=('Bold', 30)) 115 | lb.pack() 116 | contact_frame.pack(padx=20) 117 | 118 | 119 | def about_page(): 120 | about_frame = tk.Frame(main_frame) 121 | lb = tk.Label(about_frame, text='About Page\n\nPage:4', font=('Bold', 30)) 122 | lb.pack() 123 | about_frame.pack(padx=20) 124 | 125 | 126 | def hide_indicators(): 127 | home_indicate.config(bg='#c3c3c3') 128 | menu_indicate.config(bg='#c3c3c3') 129 | contact_indicate.config(bg='#c3c3c3') 130 | about_indicate.config(bg='#c3c3c3') 131 | 132 | 133 | def delete_pages(): 134 | for frame in main_frame.winfo_children(): 135 | frame.destroy() 136 | 137 | 138 | def indicate(lb, page): 139 | hide_indicators() 140 | lb.config(bg='#158aff') 141 | delete_pages() 142 | page() 143 | 144 | 145 | options_frame = tk.Frame(root, bg='#c3c3c3') 146 | 147 | home_button = tk.Button(options_frame, text='Dashboard', font=('Bold', 15), 148 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(home_indicate, home_page)) 149 | home_button.place(x=70, y=70) 150 | 151 | home_indicate = tk.Label(options_frame, text='', bg='#c3c3c3') 152 | home_indicate.place(x=60, y=74, width=5, height=30) 153 | 154 | menu_button = tk.Button(options_frame, text='Schedule', font=('Bold', 15), 155 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(menu_indicate, menu_page)) 156 | menu_button.place(x=70, y=120) 157 | 158 | menu_indicate = tk.Label(options_frame, text='', bg='#c3c3c3') 159 | menu_indicate.place(x=60, y=124, width=5, height=30) 160 | 161 | contact_button = tk.Button(options_frame, text='History', font=('Bold', 15), 162 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(contact_indicate, contact_page)) 163 | contact_button.place(x=70, y=170) 164 | 165 | contact_indicate = tk.Label(options_frame, text='', bg='#c3c3c3') 166 | contact_indicate.place(x=60, y=174, width=5, height=30) 167 | 168 | about_button = tk.Button(options_frame, text='Settings', font=('Bold', 15), 169 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(about_indicate, about_page)) 170 | about_button.place(x=70, y=220) 171 | 172 | logout_button = tk.Button(options_frame, text='Logout', font=('Bold', 15), 173 | fg='#158aff', bd=0, bg='#c3c3c3') 174 | logout_button.place(x=70, y=270) 175 | 176 | about_indicate = tk.Label(options_frame, text='', bg='#c3c3c3') 177 | about_indicate.place(x=60, y=224, width=5, height=30) 178 | 179 | options_frame.pack(side=tk.LEFT) 180 | options_frame.pack_propagate(False) 181 | options_frame.config(width=240, height=700) 182 | 183 | main_frame = tk.Frame(root, highlightbackground='black', highlightthickness=2) 184 | main_frame.pack(side=tk.LEFT) 185 | main_frame.pack_propagate(False) 186 | main_frame.configure(width=1010, height=700) 187 | 188 | root.mainloop() 189 | -------------------------------------------------------------------------------- /AgroDesktop/dash01.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | from tkinter import * 3 | # from tkinter import messagebox 4 | import mysql.connector 5 | import cv2 6 | from PIL import Image, ImageTk 7 | #from ml_module import MLModel # Import the MLModel class 8 | import numpy as np 9 | import matplotlib.pyplot as plt 10 | import pandas as pd 11 | #import testZ as db 12 | # import numpy as np 13 | # import tensorflow as tf 14 | # from keras.preprocessing import image 15 | # from keras.applications.resnet50 import preprocess_input 16 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 17 | from matplotlib.figure import Figure 18 | 19 | 20 | root = Tk() 21 | root.title("AGRODIAGNOBOT System") 22 | root.geometry("1250x700+210+100") 23 | 24 | # icon image 25 | image_icon = PhotoImage(file="image/icon.png") 26 | root.iconphoto(False, image_icon) 27 | 28 | camera_label = None 29 | 30 | 31 | def home_page(): 32 | global camera_label 33 | home_frame = Frame(main_frame) 34 | 35 | lb = tkinter.Label(home_frame, text='Home Page : Camera Output ', font=('Bold', 15)) 36 | lb.pack() 37 | 38 | 39 | 40 | # OpenCV code to capture webcam feed 41 | cap = cv2.VideoCapture(0) 42 | 43 | # Create a label for displaying the camera feed 44 | camera_label = Label(home_frame) 45 | 46 | def update_camera(): 47 | ret, frame = cap.read() 48 | if ret: 49 | frame = cv2.resize(frame, (360, 250)) 50 | 51 | # Convert the OpenCV image to Tkinter PhotoImage 52 | img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 53 | img = Image.fromarray(img) 54 | img = ImageTk.PhotoImage(img) 55 | 56 | # Update label with the new image 57 | camera_label.config(image=img) 58 | camera_label.image = img 59 | 60 | # Call itself after 10 milliseconds 61 | root.after(10, update_camera) 62 | 63 | # Create a label for displaying the camera feed 64 | 65 | camera_label = tkinter.Label(home_frame) 66 | camera_label.pack() 67 | 68 | # Start updating the camera feed 69 | update_camera() 70 | 71 | prediction_class_lb = tkinter.Label(home_frame, text='Prediction Class name : late-blight ') 72 | prediction_class_lb.pack() 73 | percentage_class_lb = tkinter.Label(home_frame, text='Percentage : 96.46% ') 74 | percentage_class_lb.pack() 75 | 76 | # Bar chart plotting code 77 | mydb = mysql.connector.connect(host="localhost", 78 | user="root", 79 | password="your password", 80 | database="database name") 81 | mycursor = mydb.cursor() 82 | mycursor.execute("select Name, Marks from student_marks") 83 | result = mycursor.fetchall() 84 | 85 | Names = [] 86 | Marks = [] 87 | 88 | for i in result: 89 | Names.append(i[0]) 90 | Marks.append(i[1]) 91 | 92 | # Matplotlib bar chart 93 | fig, ax = plt.subplots(figsize=(10,6)) 94 | colors = np.random.rand(len(Names), 3) 95 | ax.bar(Names, Marks, color=colors) 96 | ax.set_ylim(0, 100) 97 | ax.set_xlabel("Name of Students") 98 | ax.set_ylabel("Marks of Students") 99 | ax.set_title("Student's Information") 100 | 101 | # Embedding Matplotlib plot in Tkinter 102 | canvas = FigureCanvasTkAgg(fig, master=home_frame) 103 | canvas_widget = canvas.get_tk_widget() 104 | canvas_widget.pack() 105 | 106 | # Pie chart plotting code 107 | my_dict = {'NAME': ['Infant', 'Child', 'Young', 'Old'], 'Nos': [30, 40, 50, 50]} 108 | df = pd.DataFrame(data=my_dict) 109 | lbl = ['Infant', 'Child', 'Young', 'Old'] 110 | fig1, ax1 = plt.subplots(figsize=(3, 3)) 111 | ax1.pie(df['Nos'], labels=lbl, autopct='%1.1f%%', startangle=90) 112 | ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle. 113 | 114 | # Embedding Matplotlib pie chart in Tkinter 115 | pie_canvas = FigureCanvasTkAgg(fig1, master=home_frame) 116 | pie_widget = pie_canvas.get_tk_widget() 117 | pie_widget.pack() 118 | 119 | home_frame.pack(padx=20) 120 | 121 | 122 | def menu_page(): 123 | menu_frame = Frame(main_frame) 124 | 125 | lb = tkinter.Label(menu_frame, text='Menu Page\n\nPage:2', font=('Bold', 30)) 126 | lb.pack() 127 | 128 | menu_frame.pack(padx=20) 129 | 130 | 131 | def contact_page(): 132 | contact_frame = Frame(main_frame) 133 | 134 | lb = tkinter.Label(contact_frame, text='Contact Page\n\nPAge:3', font=('Bold', 30)) 135 | lb.pack() 136 | 137 | contact_frame.pack(padx=20) 138 | 139 | 140 | def about_page(): 141 | about_frame = Frame(main_frame) 142 | 143 | lb = tkinter.Label(about_frame, text='About Page\n\nPAge:4', font=('Bold', 30)) 144 | lb.pack() 145 | 146 | about_frame.pack(padx=20) 147 | 148 | 149 | def hide_indicators(): 150 | home_indicate.config(bg='#c3c3c3') 151 | menu_indicate.config(bg='#c3c3c3') 152 | contact_indicate.config(bg='#c3c3c3') 153 | about_indicate.config(bg='#c3c3c3') 154 | 155 | 156 | def delete_pages(): 157 | for frame in main_frame.winfo_children(): 158 | frame.destroy() 159 | 160 | 161 | def indicate(lb, page): 162 | hide_indicators() 163 | lb.config(bg='#158aff') 164 | delete_pages() 165 | page() 166 | 167 | 168 | options_frame = tkinter.Frame(root, bg='#c3c3c3') 169 | 170 | ##home button 171 | home_button = tkinter.Button(options_frame, text='Home', font=('Bold', 15), 172 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(home_indicate, home_page)) 173 | 174 | home_button.place(x=80, y=70) 175 | 176 | home_indicate = tkinter.Label(options_frame, text='', bg='#c3c3c3') 177 | home_indicate.place(x=60, y=74, width=5, height=30) 178 | 179 | ##menu button 180 | menu_button = tkinter.Button(options_frame, text='Menu', font=('Bold', 15), 181 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(menu_indicate, menu_page)) 182 | 183 | menu_button.place(x=80, y=120) 184 | 185 | menu_indicate = tkinter.Label(options_frame, text='', bg='#c3c3c3') 186 | menu_indicate.place(x=60, y=124, width=5, height=30) 187 | 188 | ##contact button 189 | contact_button = tkinter.Button(options_frame, text='Contact', font=('Bold', 15), 190 | fg='#158aff', bd=0, bg='#c3c3c3', 191 | command=lambda: indicate(contact_indicate, contact_page)) 192 | 193 | contact_button.place(x=80, y=170) 194 | 195 | contact_indicate = tkinter.Label(options_frame, text='', bg='#c3c3c3') 196 | contact_indicate.place(x=60, y=174, width=5, height=30) 197 | 198 | ##about button 199 | about_button = tkinter.Button(options_frame, text='About', font=('Bold', 15), 200 | fg='#158aff', bd=0, bg='#c3c3c3', command=lambda: indicate(about_indicate, about_page)) 201 | 202 | about_button.place(x=80, y=220) 203 | 204 | about_indicate = tkinter.Label(options_frame, text='', bg='#c3c3c3') 205 | about_indicate.place(x=60, y=224, width=5, height=30) 206 | 207 | options_frame.pack(side=tkinter.LEFT) 208 | options_frame.pack_propagate(False) 209 | options_frame.config(width=240, height=700) 210 | 211 | main_frame = tkinter.Frame(root, highlightbackground='black', highlightthickness=2) 212 | 213 | main_frame.pack(side=tkinter.LEFT) 214 | main_frame.pack_propagate(False) 215 | main_frame.configure(width=1010, height=700) 216 | 217 | root.mainloop() 218 | --------------------------------------------------------------------------------