Используя мою обученную модель в представлениях, не позволяет мне отображать новые возвращаемые значения

требуется время, чтобы загрузить все данные в новый df_with_ṕredictions, моя проблема в том, как я могу отобразить новую таблицу с этими предсказаниями в шаблоне :

def home(request):
    df = None
    df_with_predictions = None
    error_message = None
    api_key = None
    column_name = None
    predictions_html = ""  # Initialize an empty string for the DataFrame HTML

    if request.method == 'POST':
        api_key = request.POST.get('api_key_input', '')
        column_name = request.POST.get('column_name', '')

        file = request.FILES.get('file')
        if file:
            try:
                file_ext = file.name.split(".")[-1]
                if file_ext == "csv":
                    df = pd.read_csv(file)
                elif file_ext == "xlsx":
                    df = pd.read_excel(file)

                if df is not None:
                    x_new = get_embeddings(df, column_name, api_key)
                    if x_new is not None:
                        new_predictions = classify_comments(x_new)
                        df_with_predictions = df.copy()
                        df_with_predictions['Clasificación_gpt_'] = new_predictions
                        print("File has been processed and predictions are added. in home")
                        print(df_with_predictions)
                        # Convert DataFrame to HTML
                        predictions_html = df_with_predictions.to_html(classes="table table-striped", index=False)
            except Exception as e:
                error_message = str(e)

    context = {
        'api_key': api_key,
        'column_name': column_name,
        'predictions_html': predictions_html,  # Pass the HTML to the template
        'error_message': error_message
    }
    return render(request, "home.html", context)

Я попробовал разместить все переменные в одном посте для манипулирования ими в домашних представлениях, но у меня все еще возникают проблемы

Вот что я вижу на терминале:

** Прогнозы:

[3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 2 3 3 3]

Файл был обработан, и предсказания добавлены. in home

raiz  ... Clasificacióngpt

0 1.0 ... 3 1 2.0 ... 3 2 4.0 ... 3 3 11.0 ... 3 4 12.0 ... 3 5 15.0 ... 3 6 17.0 ... 3 7 22.0 ... 3 8 24.0 ... 2 9 NaN ... 3 10 NaN ... 3 11 NaN ... 3 12 NaN ... 3 13 NaN ... 3 14 NaN ... 3 15 NaN ... 3 16 25.0 ... 2 17 26.0 ... 3 18 NaN ... 3 19 NaN ... 3<

>

[20 строк x 5 столбцов]

[27/Apr/2024 16:06:16] "POST /home/ HTTP/1.1" 200 13738

Вернуться на верх