Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,11 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import re
|
4 |
|
5 |
-
def calculate_correlations(
|
6 |
try:
|
7 |
-
df = pd.read_csv(
|
8 |
-
|
9 |
-
# Преобразование 'Soon ' ДО применения pd.to_numeric
|
10 |
-
df['Soon '] = df['Soon '].str.replace(' из 5', '')
|
11 |
-
df['Soon '] = pd.to_numeric(df['Soon '].astype(str).str.replace(',', '.'), errors='coerce')
|
12 |
-
|
13 |
-
# 1. Оценка и наличие отзыва
|
14 |
-
df['has_review'] = df['Cam'].notna().astype(int)
|
15 |
-
correlation_review = df['Soon '].corr(df['has_review'])
|
16 |
-
|
17 |
-
# 2. Оценка и тип размещения (приблизительно)
|
18 |
-
accommodation_types = ['кемпер', 'палатка', 'бунгало', 'мобильный дом']
|
19 |
-
correlation_accommodation = {}
|
20 |
-
for acc_type in accommodation_types:
|
21 |
-
df[acc_type] = df['Cam'].apply(lambda x: 1 if isinstance(x, str) and re.search(acc_type, x, re.IGNORECASE) else 0)
|
22 |
-
correlation_accommodation[acc_type] = df['Soon '].corr(df[acc_type])
|
23 |
-
|
24 |
-
# 3. Оценка и статус эксперта
|
25 |
-
df['is_expert'] = df['Exp'].apply(lambda x: 1 if isinstance(x, str) and 'местный эксперт' in x.lower() else 0)
|
26 |
-
correlation_expert = df['Soon '].corr(df['is_expert'])
|
27 |
|
|
|
28 |
|
29 |
return {
|
30 |
"correlation_review": correlation_review,
|
@@ -39,10 +21,10 @@ def calculate_correlations(file_path):
|
|
39 |
|
40 |
iface = gr.Interface(
|
41 |
fn=calculate_correlations,
|
42 |
-
inputs=gr.File(type="
|
43 |
-
outputs=gr.JSON(),
|
44 |
title="Корреляционный анализ отзывов",
|
45 |
description="Загрузите CSV файл с отзывами."
|
46 |
)
|
47 |
|
48 |
-
iface.launch(share=True)
|
|
|
2 |
import pandas as pd
|
3 |
import re
|
4 |
|
5 |
+
def calculate_correlations(file_obj): # Принимаем объект файла
|
6 |
try:
|
7 |
+
df = pd.read_csv(file_obj.name) # Читаем CSV из объекта файла
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
# ... (остальной код для расчета корреляций без изменений) ...
|
10 |
|
11 |
return {
|
12 |
"correlation_review": correlation_review,
|
|
|
21 |
|
22 |
iface = gr.Interface(
|
23 |
fn=calculate_correlations,
|
24 |
+
inputs=gr.File(type="filepath", label="CSV файл с отзывами"), # Изменено на type="filepath"
|
25 |
+
outputs=gr.JSON(),
|
26 |
title="Корреляционный анализ отзывов",
|
27 |
description="Загрузите CSV файл с отзывами."
|
28 |
)
|
29 |
|
30 |
+
iface.launch(share=True)
|