|
import gradio as gr |
|
import pandas as pd |
|
import re |
|
|
|
def calculate_correlations(file_obj): |
|
try: |
|
|
|
for sep in [',', ';', '\t']: |
|
try: |
|
df = pd.read_csv(file_obj.name, sep=sep, encoding='utf-8') |
|
break |
|
except pd.errors.ParserError: |
|
pass |
|
|
|
if 'df' not in locals(): |
|
return {"error": "Ошибка парсинга файла. Не удалось прочитать CSV с разными разделителями."} |
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
return {"error": f"Неизвестная ошибка: {e}"} |
|
|
|
iface = gr.Interface( |
|
fn=calculate_correlations, |
|
inputs=gr.File(type="filepath", label="CSV файл с отзывами"), |
|
outputs=gr.JSON(), |
|
title="Корреляционный анализ отзывов", |
|
description="Загрузите CSV файл с отзывами." |
|
) |
|
|
|
iface.launch() |