Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Faisu #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions Faisu
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 01 21:36:00 2022

@author: F2I
"""

from numpy import *
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tkinter import *
from PIL import ImageTk, Image  
from tkinter import filedialog  



def wrt(st,fname):
    file = open(fname,"w+")
    file.write(st)
    file.close() 



def red(fname):    
    file = open(fname,"r")
    f=file.read()
    file.close() 
    return f


def open_img():
   try: 
      x = openfilename()
      wrt(x,"upload");print(x);
      img =Image.open(x)
   except:
      x = 'images/error.png'
      print(x);
      img =Image.open(x)
   img = img.resize((325, 200), Image.ANTIALIAS) 
   img = ImageTk.PhotoImage(img) 
   panel = Label(root, image = img) 
   panel.image = img 
   panel.place(x=455, y=100)



def openfilename(): 
   filename = filedialog.askopenfilename(title ='UPLOAD IMAGE') 
   return filename 



def callback():  
  patient="\n IMAGE FILE NOT UPLOADED..."  
  try:
    model = load_model('models/pneumonia.h5')
    #model.summary()
    test_image=image.load_img(red("upload"),target_size=(224,224,3))
    #imgplot = plt.imshow(test_image)
    #plt.show()
    test_image=image.img_to_array(test_image)
    test_image=expand_dims(test_image,axis=0)
    result = model.predict(test_image)
    patient="PNEUMONIA" if result[0][0]==1 else "  NORMAL"
    output.set("\n      "+patient+" DETECTED !\n");print(patient)
  except:
    output.set(patient);print("EXCEPTION")



root = Tk() 
root.title("PNEUMONIA") 
output=StringVar();
root.attributes('-fullscreen',True)

#root.geometry("500x500")
#root['bg'] = 'black'

background = PhotoImage(file = "images/cover_pn.png")
Label(root,image = background).place(x=0, y=0)

#root.resizable(width = True, height = True) 

img =Image.open("images/input.png")
img = img.resize((325, 200), Image.ANTIALIAS) 
img = ImageTk.PhotoImage(img) 
panel = Label(root, image = img) 
panel.image = img 
panel.place(x=455, y=100)

upload = PhotoImage(file = r"images/upload.png")
Button(root, text = "upload",bd=0,highlightthickness=0,image = upload,
             command = open_img).place(x=150, y=150)


Label(root, text="\nOUTPUT\n",
           width=25,
           font=("Bauhaus 93", 20)).place(x=432, y=335)
Label(root, text="",textvariable = output,
                    font=("Bauhaus 93", 20)).place(x=432, y=335)


detect = PhotoImage(file = r"images/detect.png")
Button(root, text="detect",bd=0,highlightthickness=0,image = detect,
                            command = callback).place(x=150,y=340)


close = PhotoImage(file = r"images/home.png")
Button(root, text = "close",image = close,highlightthickness=0,
                            command = root.destroy).place(x=0,y=0)  


root.mainloop()