I try to call pandasgui after pressing a button and choosing a file using kivy framework, the process works fine and pandasgui behave in a normal manner but when i try to comeback to kivy it freezes and i should restart the app,I was being told that i should use threading but i'm still not sure how to proceed , any ideas ?
function call when button clicked :
import kivy
from pandasgui import show
# this restrict the kivy version i.e
# below this kivy version you cannot
# use the app or software
kivy.require("1.9.1")
# base Class of your App inherits from the App class.
# app:always refers to the instance of your application
from kivy.app import App
# creates the button in kivy
# if not imported shows the error
from kivy.uix.button import Button
# class in which we are creating the button
class ButtonApp(App):
def build(self):
# use a (r, g, b, a) tuple
btn = Button(text="Push Me !",
font_size="20sp",
background_color=(1, 1, 1, 1),
color=(1, 1, 1, 1),
size=(32, 32),
size_hint=(.2, .2),
pos=(300, 250))
# bind() use to bind the button to function callback
btn.bind(on_press=self.callback)
return btn
# callback function tells when button pressed
def callback(self, event):
import pandas as pd
import pickle
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
data_test = pd.read_csv('test_data.csv')
# Extract test labels from data_test
y_test = data_test['target']
# Extract test data
X_test = data_test.iloc[:, 1:-1]
# Load pre-trained data
loaded_model = pickle.load(open(r'GVHD.sav', 'rb'))
# Predict labels
y_pred = loaded_model.predict(X_test)
# disp.figure_.savefig(r'C:\Users\44755\Downloads\confusion_matrix.jpg')
# Concatenate all test data
from matplotlib import pyplot as plt
new_data = pd.concat([X_test, y_test, pd.DataFrame(y_pred, columns=['Predicted response'])], axis=1)
# Save output
new_data.to_csv(r'GVHD_Output_data.csv', index=False)
# Create confusion matrix
disp = ConfusionMatrixDisplay(confusion_matrix=confusion_matrix(y_test,
y_pred,
labels=[0, 1],
normalize='true'),
display_labels=['low risk', 'high risk'])
disp = disp.plot(cmap=plt.cm.Blues)
# Save confusion matrix
disp.figure_.savefig('confusion_matrix_GVHD.jpg')
df = pd.read_csv('GVHD_Output_data.csv')
show(df)
# creating the object root for ButtonApp() class
root = ButtonApp()
root.run()