diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..c7d9f3332a950355d5a77d85000f05e6f45435ea --- /dev/null +++ b/.gitattributes @@ -0,0 +1,34 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cfefe10494eb373ef1532d1fcfe8c145e2ad3314 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +--- +title: PrafullInterfaces +emoji: 📉 +colorFrom: indigo +colorTo: purple +sdk: gradio +sdk_version: 3.28.0 +app_file: app.py +pinned: false +license: openrail +duplicated_from: prafullcodes/PrafullInterfaces +--- + +Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference diff --git a/app.py b/app.py new file mode 100644 index 0000000000000000000000000000000000000000..7e730484bf8b0d2c7d818f5dcbfeea15d2a12756 --- /dev/null +++ b/app.py @@ -0,0 +1,228 @@ +# -*- coding: utf-8 -*- +"""lung cancerdetection.ipynb + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1f7VybSnYLPbUVLRLMNQboxQkCYaBCXMs +""" + + +# This Python 3 environment comes with many helpful analytics libraries installed +# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python +# For example, here's several helpful packages to load + +import numpy as np # linear algebra +import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) + +# Input data files are available in the read-only "../input/" directory +# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory + +import os + + +# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" +# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session + +# importing libraries + +import tensorflow as tf +from tensorflow.keras.layers import Input, Lambda, Dense, Flatten +from tensorflow.keras.models import Model +from tensorflow.keras.applications.resnet50 import ResNet50 +from tensorflow.keras.applications.resnet50 import preprocess_input +from tensorflow.keras.preprocessing import image +from tensorflow.keras.preprocessing.image import ImageDataGenerator,load_img +from tensorflow.keras.models import Sequential +import numpy as np +from glob import glob +import matplotlib.pyplot as plt + +image_set = "./lung_image_sets" + +SIZE_X = SIZE_Y = 224 + +datagen = tf.keras.preprocessing.image.ImageDataGenerator(validation_split = 0.2) + +train_set = datagen.flow_from_directory(image_set, + class_mode = "categorical", + target_size = (SIZE_X,SIZE_Y), + color_mode="rgb", + batch_size = 128, + shuffle = False, + subset='training', + seed = 42) + +validate_set = datagen.flow_from_directory(image_set, + class_mode = "categorical", + target_size = (SIZE_X, SIZE_Y), + color_mode="rgb", + batch_size = 128, + shuffle = False, + subset='validation', + seed = 42) + + +IMAGE_SIZE = [224, 224] + +resnet = ResNet50(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False) + +# don't train existing weights +for layer in resnet.layers: + layer.trainable = False + +flatten = Flatten()(resnet.output) +dense = Dense(256, activation = 'relu')(flatten) +dense = Dense(128, activation = 'relu')(dense) +prediction = Dense(3, activation = 'softmax')(dense) + +#creating a model +model = Model(inputs = resnet.input, outputs = prediction ) + +model.summary() + +model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy']) + +#executing the model +history = model.fit(train_set, validation_data = (validate_set), epochs = 8, verbose = 1) + +# plotting the loss +plt.plot(history.history['loss'],label = 'train_loss') +plt.plot(history.history['val_loss'], label = 'testing_loss') +plt.title('loss') +plt.legend() +plt.show() + +# Both Validation and Training accuracy is shown here + +plt.plot(history.history['accuracy'], label='training_accuracy') +plt.plot(history.history['val_accuracy'], label='validation accuracy') +plt.title('Accuracy') +plt.legend() +plt.show() + +# CHECKING THE CONFUSION MATRIX + +from sklearn.metrics import classification_report +from sklearn.metrics import confusion_matrix +from sklearn.metrics import f1_score +Y_pred = model.predict(validate_set) +y_pred = np.argmax(Y_pred ,axis =1) +print('Confusion Matrix') +confusion_matrix = confusion_matrix(validate_set.classes, y_pred) +print(confusion_matrix) +print('Classification Report') +target_names = ['aca','n', 'scc'] +print(classification_report(validate_set.classes, y_pred, target_names=target_names)) + +result = model.evaluate(validate_set,batch_size=128) +print("test_loss, test accuracy",result) + +import pickle + +with open('model_pkl', 'wb') as files: + pickle.dump(model, files) + +# img = tf.keras.utils.load_img('/content/lung_colon_image_set/lung_image_sets/lung_aca/lungaca1.jpeg', target_size=(224, 224)) +# img_array = tf.keras.utils.img_to_array(img) +# img_array = tf.expand_dims(img_array, 0) + +# # load saved model +# with open('model_pkl' , 'rb') as f: +# lr = pickle.load(f) +# predi=lr.predict(img_array) +# print(predi) +# image_output_class=target_names[np.argmax(predi)] + +# print("The predicted class is", image_output_class) + +import gradio as gd +from PIL import Image + +css_class=""" +body{ background-color:rgb(10, 30, 75)} +ul>li{ + text-decoration: none; + list-style:none; + margin: 1px; + padding:.5px +} +h3{ + color: rgb(24, 46, 98); + margin: 1px; + padding:.5px + text-align: center; +} +h4{ + text-decoration: underline; + color: rgb(218, 57, 57); + text-align: center; +} + +""" +def acaClassOutput(): + return ''' +

You CT Scan Report:-

+
+

You have Adenocarcinoma type cancer

+

It is Non-small cell type cancer which has effected you 40% of lung cells.

+ + ''' + +def sccClassOutput(): + return ''' +

You CT Scan Report:-

+
+

You have Squamous type cancer

+

It effects the broncial tube of lungs. You probably have smoke history as it effected your 30% lungs

+