1 2 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| import matplotlib as plt
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from tkinter import *
from tkinter import filedialog
import tkinter as tk
import pandas as pd
global nucl , percent,symb
import io
from keras.models import load_model
from keras.preprocessing import image
import numpy as np
class mclass:
global color
color="white"
def __init__(self, root):
self.logo = PhotoImage(file="/Users/imed/Desktop/interface/rium.png")
self.root = root
#helv36 = tkFont.Font(family='Helvetica', size=14, weight='bold')
self.nucl= StringVar()
self.percent=StringVar()
self.symb=StringVar()
self.symb.set("%")
self.root.wm_title("Isotope Tdentification")
self.frame = tk.Frame(master=self.root)
self.frame.pack(fill=tk.BOTH, expand=1)
self.figure = Figure(figsize=(5, 4), dpi=100)
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvasTkAgg(self.figure, master=self.frame)
self.canvas.draw()
self.canvas.get_tk_widget().place(x=10, y =40, width=450, height=400)
self.label = tk.Label(master=self.frame,textvariable=self.nucl,bg="red")
self.label.place(x=50, y=10)
# Utilisation d'une fermeture, les valeurs de canvas et figure sont capturées
self.button = tk.Button(master=self.frame, text='Verifier', command=self.learn)
self.button.pack(side=tk.BOTTOM)
self.button = tk.Button(master=self.frame, text='Graphe', command=self.plot)
self.button.pack(side=tk.BOTTOM)
self.button = tk.Button(master=self.frame, text='Parcourir', command=self.askopenfile)
self.button.pack(side=tk.BOTTOM)
self.toolbar = NavigationToolbar2Tk(self.canvas,self.frame )
#toolbar.config(background=color)
self.toolbar.update()
self.toolbar.pack(side=tk.BOTTOM)
def askopenfile(self):
self.fil=filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("xlsx files","*.xlsx"),("all files","*.*")))
def plot (self):
self.xl = pd.ExcelFile(self.fil)
self.df1 = self.xl.parse('Spectre')
self.coups=self.df1['Coups']
self.energie=self.df1['Energie (keV)']
self.fig = Figure(figsize=(5,4), dpi=100)
self.figure.canvas.draw()
if self.fig.axes:
self.figure.delaxes(figure.axes[0])
#axes = figure.add_subplot(111)
self.a = self.fig.add_subplot(111)
self.a.set_facecolor(color)
self.a.plot(self.energie,self.coups,'k')
self.a.vlines(x=self.energie,ymin=0,ymax=self.coups,color='black')
self.imag = io.BytesIO()
self.figure.savefig(self.imag, format='png')
self.imag.seek(0)
#return self.imag
def learn(self):
model = load_model('/Users/imed/Desktop/new_model_200.h5')
self.nucleide=['Mn','U','Cs','Am','Na','Co60','Y','Sr']
self.img = image.load_img(self.imag, target_size=(128, 128))
self.x = image.img_to_array(self.img)
self.x = np.expand_dims(self.x, axis=0)
self.images = np.vstack([self.x])
self.classes = model.predict_classes(self.images/255)
print(self.nucleide[self.classes[0]])
self.nucl.set(self.nucleide[self.classes[0]])
root= Tk()
root.geometry("623x552")
root.title()
#window.configure(background=color)
start= mclass (root)
root.mainloop() |
Partager