boompack commited on
Commit
c60844b
·
verified ·
1 Parent(s): 3a54228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -2,11 +2,28 @@ import gradio as gr
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,
@@ -15,16 +32,16 @@ def calculate_correlations(file_obj): # Принимаем объект файл
15
  }
16
 
17
  except Exception as e:
18
- return f"Ошибка: {e}"
19
 
20
 
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)
 
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)
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
  return {
29
  "correlation_review": correlation_review,
 
32
  }
33
 
34
  except Exception as e:
35
+ return {"error": str(e)} # Возвращаем словарь с ошибкой
36
 
37
 
38
 
39
  iface = gr.Interface(
40
  fn=calculate_correlations,
41
+ inputs=gr.File(type="filepath", label="CSV файл с отзывами"),
42
  outputs=gr.JSON(),
43
  title="Корреляционный анализ отзывов",
44
  description="Загрузите CSV файл с отзывами."
45
  )
46
 
47
+ iface.launch()