Skip to content

Commit

Permalink
conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
elizaveta-andreeva committed Sep 15, 2023
2 parents d9db6cc + c81f66c commit 35a57c0
Show file tree
Hide file tree
Showing 20 changed files with 309 additions and 140 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PEP8 Style Guide Enforcement

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r emotional_speech_recognizing/requirements.txt
pip install -r silero_demo/requirements.txt
pip install pylint
- name: Run Pylint
run: |
pylint $(git ls-files '*.py')
75 changes: 75 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[BASIC]

argument-naming-style=snake_case
attr-naming-style=snake_case

bad-names=
foo,
bar,
baz,
toto,
tutu,
tata

class-const-naming-style=UPPER_CASE
class-naming-style=PascalCase
const-naming-style=UPPER_CASE
docstring-min-length=-1
function-naming-style=snake_case
method-naming-style=snake_case
module-naming-style=snake_case
variable-naming-style=snake_case


[MESSAGES CONTROL]
disable=
fixme,
missing-module-docstring,
missing-class-docstring,
missing-function-docstring,
consider-using-dict-items,
consider-iterating-dictionary,
too-few-public-methods,
unspecified-encoding,
consider-using-enumerate,
subprocess-run-check,
redefined-outer-name,
no-member,
unused-argument,
protected-access,
duplicate-code,
missing-timeout,
cyclic-import # это сложно поправить быстро

enable=
import-error,
invalid-name,
unused-import,
missing-final-newline,
line-too-long,
wrong-import-order,
wildcard-import,
trailing-whitespace,
unused-wildcard-import,
trailing-newlines,
redefined-builtin,
singleton-comparison,
unused-variable,
no-else-return,
f-string-without-interpolation,
ungrouped-imports,
too-many-arguments,
consider-using-with,
inconsistent-return-statements,
simplifiable-condition,
reimported,
super-with-arguments

[FORMAT]
max-line-length=150
max-module-lines=1000

[DESIGN]
max-args=9
max-branches=12
max-returns=6
2 changes: 1 addition & 1 deletion TestPayment/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BOT_TOKEN = '1764779366:AAHPNU-fgWI1PEl_odMuNFMf7E767lHfKC4'
PROVIDER_TOKEN = '401643678:TEST:e1dc6c64-5f3f-4d0d-a7c7-f2f2bea0aa4e'
PROVIDER_TOKEN = '401643678:TEST:e1dc6c64-5f3f-4d0d-a7c7-f2f2bea0aa4e'
6 changes: 3 additions & 3 deletions TestPayment/pay_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import logging
import config

from telegram import LabeledPrice, ShippingOption, Update
from telegram import LabeledPrice, Update
from telegram.ext import (
Updater,
CommandHandler,
MessageHandler,
Filters,
PreCheckoutQueryHandler,
ShippingQueryHandler,
CallbackContext,
)

Expand All @@ -37,7 +36,8 @@ def start_without_shipping_callback(update: Update, context: CallbackContext) ->
description = "Payment Example using python-telegram-bot"
# select a payload just for you to recognize its the donation from your bot
payload = "Custom-Payload"
# In order to get a provider_token see https://core.telegram.org/bots/payments#getting-a-token
# In order to get a provider_token see
# https://core.telegram.org/bots/payments#getting-a-token
provider_token = config.PROVIDER_TOKEN
start_parameter = "test-payment"
currency = "RUB"
Expand Down
15 changes: 10 additions & 5 deletions audio_classes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from dataclasses import dataclass


Expand All @@ -24,10 +23,16 @@ def __add_word(self, word, start, end, conf):
def generate_output_info(self):
answer_list = [f"Полученное предложение: \n{self._text}\nСтатистика по сообщению:\n"]
for i in self._words:
answer_list.append(f"Слово \"{i.word}\" было сказано в промежутке {i.begin_timestamp} - {i.end_timestamp} с "
f"вероятностью {i.probability}\n")
answer_list.append(
f"Слово \"{i.word}\" было сказано в промежутке {i.begin_timestamp} - {i.end_timestamp} с "
f"вероятностью {i.probability}\n"
)
return "".join(answer_list)

def generate_stats(self):
return '\n'.join([f"{i.word} - {i.begin_timestamp} - {i.end_timestamp} - {i.probability}" for i in self._words])

return '\n'.join(
[
f"{i.word} - {i.begin_timestamp} - {i.end_timestamp} - {i.probability}"
for i in self._words
]
)
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3"

services:
db:
image: mongo
image: mongo:6.0
restart: unless-stopped
env_file: .env
volumes:
Expand All @@ -22,7 +22,7 @@ services:
- db

silero-tts-service:
image: "navatusein/silero-tts-service"
image: "navatusein/silero-tts-service:1.0.0"
container_name: "silero-tts-service"
restart: unless-stopped
env_file: .env
Expand Down
36 changes: 20 additions & 16 deletions emotional_speech_recognizing/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import os
import time
import numpy as np

import librosa
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
#from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import EarlyStopping
#from sklearn.preprocessing import LabelEncoder
#from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten
#from tensorflow.keras.layers import LSTM
import time
from keras.models import Sequential
from keras.layers import Dense
from keras.callbacks import EarlyStopping

start_time = time.time()

# Путь к папке с датасетом
dataset_dir = r'AudioData'
DATASET_DIR = r'AudioData'

# Список эмоций и соответствующих меток
emotions = {'a': 0, 'd': 1, 'f': 2, 'h': 3, 'n': 4, 'sa': 5, 'su': 6}
Expand All @@ -26,7 +23,7 @@
# Проход по каждой эмоции в папке датасета
for emotion in emotions.keys():
# Путь к папке с эмоцией
emotion_dir = os.path.join(dataset_dir, emotion)
emotion_dir = os.path.join(DATASET_DIR, emotion)

# Проход по каждому аудиофайлу в папке с эмоцией
for file in os.listdir(emotion_dir):
Expand All @@ -50,20 +47,27 @@
# Создание модели нейронной сети
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=(X_train.shape[1],)))
#model.add(Dropout(0.5))
# model.add(Dropout(0.5))
model.add(Dense(100, activation='relu'))
#model.add(Dense(15, activation='relu'))
#model.add(Dense(120, activation='relu'))
#model.add(Dropout(0.5))
# model.add(Dense(15, activation='relu'))
# model.add(Dense(120, activation='relu'))
# model.add(Dropout(0.5))
model.add(Dense(len(emotions), activation='softmax'))

# Компиляция модели
#model.compile(loss='sparse_categorical_crossentropy', optimizer=Adam(learning_rate=0.001), metrics=['accuracy'])
# model.compile(loss='sparse_categorical_crossentropy', optimizer=Adam(learning_rate=0.001), metrics=['accuracy'])
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

# Обучение модели
early_stopping = EarlyStopping(monitor='val_loss', patience=10)
model.fit(X_train, y_train, epochs=50, batch_size=1, validation_data=(X_test, y_test), callbacks=[early_stopping])
model.fit(
X_train,
y_train,
epochs=50,
batch_size=1,
validation_data=(X_test, y_test),
callbacks=[early_stopping],
)

# Оценка модели на тестовой выборке
loss, accuracy = model.evaluate(X_test, y_test, verbose=0)
Expand Down
12 changes: 12 additions & 0 deletions install_all_requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

# install dependences
pip install -r requirements.txt
pip install -r emotional_speech_recognizing/requirements.txt
pip install -r silero_demo/requirements.txt

# install pylint (for checking)
pip install pylint

# install black (for autofix)
pip install black
31 changes: 9 additions & 22 deletions keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,24 @@
's_22': "22:00 - 23:00",
's_23': "23:00 - 24:00",
's_right_now': "Прямо сейчас",

'm_fun': "Веселый",
'm_sad': "Грустный",
'm_angry': "Злой",
'm_anxious': "Тревожный",
'm_urgent': "Состояние из ряда вон",

'f_tired': "Усталость",
'f_self-doubt': "Неуверенность в себе",
'f_bad': "Все плохо",
'f_lonely': "Одиноко",
'f_apathy': "Апатия",
'f_results': "Обычные итоги",
'f_groundhog': "День сурка",

'r_yes': "Да",
'r_no': "Нет",
'r_1h': "Ответить через час",

'menu_change_focus': "Сменить фокус",
'menu_share_event': "Поделиться событием",
'menu_help': "Справка"
'menu_help': "Справка",
}


Expand All @@ -38,9 +34,7 @@ def init_button(key) -> InlineKeyboardButton:


def ready_keyboard() -> InlineKeyboardMarkup:
keyboard = [
[init_button('r_yes'), init_button('r_1h')]
]
keyboard = [[init_button('r_yes'), init_button('r_1h')]]
return InlineKeyboardMarkup(keyboard)


Expand All @@ -52,7 +46,7 @@ def daily_schedule_keyboard() -> InlineKeyboardMarkup:
[init_button('s_21')],
[init_button('s_22')],
[init_button('s_23')],
[init_button('s_right_now')]
[init_button('s_right_now')],
]
return InlineKeyboardMarkup(keyboard)

Expand All @@ -61,7 +55,8 @@ def mood_keyboard() -> InlineKeyboardMarkup:
keyboard = [
[init_button('m_fun'), init_button('m_sad')],
[init_button('m_angry'), init_button('m_anxious')],
[init_button('m_urgent')], ]
[init_button('m_urgent')],
]

return InlineKeyboardMarkup(keyboard)

Expand All @@ -74,24 +69,16 @@ def focus_keyboard() -> InlineKeyboardMarkup:
[init_button('f_lonely')],
[init_button('f_apathy')],
[init_button('f_results')],
[init_button('f_groundhog')]

[init_button('f_groundhog')],
]
return InlineKeyboardMarkup(keyboard)


def yes_no_keyboard() -> InlineKeyboardMarkup:
keyboard = [
[init_button('r_yes')],
[init_button('r_no')]
]
keyboard = [[init_button('r_yes')], [init_button('r_no')]]
return InlineKeyboardMarkup(keyboard)


def menu_kyeboard() -> ReplyKeyboardMarkup:
keyboard = [
[VALUES['menu_share_event']],
[VALUES['menu_change_focus']],
[VALUES['menu_help']]
]
return ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True)
keyboard = [[VALUES['menu_share_event']], [VALUES['menu_change_focus']], [VALUES['menu_help']]]
return ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True)
1 change: 0 additions & 1 deletion my_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from bot import ask_ready, resume_survey
from db import get_schedule_list_for_feeling_ask, Schedule, get_users_not_finish_survey
from logs import init_logger


MINUTES_FOR_LOOP = 1
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ pymodm==0.4.3
pymystem3==0.2.0
cPython==0.0.6
noisereduce==2.0.1
requests==2.30.0
requests==2.30.0
torchaudio==2.0.2
whisper==1.1.10
3 changes: 3 additions & 0 deletions run_black.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

black --skip-string-normalization --skip-magic-trailing-comma --line-length=100 .
3 changes: 3 additions & 0 deletions run_pylint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

pylint $(git ls-files '*.py')
Empty file modified run_unittests.sh
100644 → 100755
Empty file.
Loading

0 comments on commit 35a57c0

Please sign in to comment.