codebox-api icon indicating copy to clipboard operation
codebox-api copied to clipboard

CodeBoxOutput is not completed

Open xiaomao23zhi opened this issue 1 year ago • 1 comments

Let's say python code as fllowing:

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

data = pd.read_csv('/mnt/data/train_data.csv')


data['label'].value_counts().plot(kind='bar')
plt.show()


X = data.drop('label', axis=1)
y = data['label']


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)


dt_model = DecisionTreeClassifier()
dt_model.fit(X_train, y_train)


y_pred = dt_model.predict(X_test)


print("accuracy: ", accuracy_score(y_test, y_pred))

This code snippet will generate 2 outputs: plt.show() and print(). According to this code,codebox-api will return on first output (plt.show()),and it seems the remaining code will not be executed.

So how can I get codebox-api to return both outputs(image/png and text)?

#edit1 typo

xiaomao23zhi avatar Feb 27 '24 09:02 xiaomao23zhi

good point currently it is checking for an image output and directly returning the image: https://github.com/shroominic/codebox-api/blob/78d5ac65d007d501400f9868f9a75fda1cbcb5ac/src/codeboxapi/box/local.py#L168C1-L173C23 (code from current work in progress v0.2 but its the same issue)

I think we can maybe cache the image and not directly return all. But also the CodeBoxOutput needs to get improved then to allow text and image output at the same time.

shroominic avatar Mar 01 '24 11:03 shroominic