MaksG commited on
Commit
6be19d7
1 Parent(s): 8427805

Update code_df_custom.py

Browse files
Files changed (1) hide show
  1. code_df_custom.py +15 -0
code_df_custom.py CHANGED
@@ -34,6 +34,21 @@ def run_code(file, code):
34
  print("No file provided")
35
  return pd.DataFrame(), "No file provided"
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def export_df(df, filename):
39
  filename = filename.replace('.xlsx', '_coded.xlsx')
 
34
  print("No file provided")
35
  return pd.DataFrame(), "No file provided"
36
 
37
+ def run_code_and_update_ui(file, code):
38
+ df, error_msg = run_code(file, code) # This is your updated run_code function.
39
+
40
+ # Now, check if there's an error message and handle it appropriately.
41
+ if error_msg:
42
+ # You can update some error display component in Gradio here to show the error_msg.
43
+ # Assuming you have a gr.Textbox to display errors:
44
+ error_display.update(value=f"Error in code execution: {error_msg}")
45
+ # Ensure you still return the original DataFrame or an empty one to satisfy the expected output type.
46
+ return df
47
+ else:
48
+ # If no error, clear the error display and return the DataFrame as usual.
49
+ error_display.update(value="")
50
+ return df
51
+
52
 
53
  def export_df(df, filename):
54
  filename = filename.replace('.xlsx', '_coded.xlsx')