Does Streamlit detect code blocks automatically?

I am displaying ChatGPT responses. When the response includes code suggestions, sometimes it automatically puts the code into a code block.
I’d like to reproduce this on purpose but can’t find a reason why streamlit can sometimes detect the code.

In the following example, the codeblock started at the 4th “import” but it seems completly random.
The responses I get look like this:
_______________________–
import java.io.File;
import java.io.IOException;

import jxl.;
import jxl.read.biff.BiffException;
import jxl.write.
;

public class XlsColumnToRow {

public static void main(String[] args) throws BiffException, IOException, WriteException {

    //Open the xls file that needs to be converted into rows and columns format
    Workbook wb = Workbook.getWorkbook(new File("input_file_name"));

    WritableWorkbook copy = Workbook.createWorkbook(new File("output_file_name"), wb);

    WritableSheet sheet1 = copy.getSheet(0);

    int rowCount = sheet1 .getRows(); //Gets the number of rows present in Sheet 1 of input xls file

    for (int i= 0 ;i<rowCount ;i++) {//Loop through each row one by one

        String cellValue1=sheet1 .getCell(0, i).getContents();//Get content from first column of current row

        for (int j= 1 ;j<4 ;j++) {//Loop through next 3 columns
            String cellValue2=sheet1 .getCell(j, i).getContents();//Get content from next three columns of current row

            Label label3 = new Label (j-1 ,i+rowCount ,cellValue2 ); //Write data to output xls file at appropriate position
            sheet1 .addCell (label3);           }         }         copy .write ();         copy .close ();         System .out .println ("Conversion completed");    }}

Any leads are highly appreciated

I suspect this is happening because of indentation

Thank you very much. That seems to be the solution!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.