-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
314 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import json | ||
import asyncio | ||
import websockets | ||
import requests | ||
|
||
auth = f"http://localhost:{json.load(open('urls.json'))['meta']}/auth" | ||
uri = f"ws://localhost:{json.load(open('urls.json'))['meta']}/" | ||
url = f"http://localhost:8080/reply" | ||
|
||
async def chat(): | ||
async with websockets.connect(uri) as websocket: | ||
token = requests.post(auth, json={"name": input("name: ")}).json()['token'] | ||
await websocket.send(f'token {token}') | ||
print('Chat started.. Say something.') | ||
while True: | ||
text = input(">>") | ||
if text == '/stop': | ||
break | ||
await websocket.send(text) | ||
text = await websocket.recv() | ||
print(f"{text}") | ||
def chat(): | ||
token = input("name: ").replace(' ', '_') | ||
print('Chat started.. Say something.') | ||
while True: | ||
text = input(">>") | ||
if text == '/stop': | ||
break | ||
reply = requests.post(url, ) | ||
text = await websocket.recv() | ||
print(f"{text}") | ||
|
||
asyncio.get_event_loop().run_until_complete(chat()) | ||
chat() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import schemes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from pydantic import BaseModel | ||
from typing import List | ||
|
||
class Tag(BaseModel): | ||
tag: str # Make Enum | ||
score: float | ||
|
||
class Token(BaseModel): | ||
tags: List[Tag] | ||
raw: str | ||
ind: int # position in the original phrase | ||
pos: str # Part of Speech; Make Enum | ||
|
||
class Speech(BaseModel): | ||
raw: str | ||
tokenized: List[Token] | ||
stylized: str | ||
args: List[Token] | ||
sentoment: float # from -1 to 1. It is not supported for now. | ||
|
||
class Author(BaseModel): | ||
is_user: bool | ||
_id: str | ||
|
||
class Replic(BaseModel): | ||
author: Author | ||
timestamp: int | ||
speech: Speech | ||
|
||
class SessionConfigs(BaseModel): | ||
local: bool = True | ||
visual: bool = False | ||
|
||
class UserSettings(BaseModel): | ||
style: bool = False | ||
confirmation_threshold: float = 1.0 | ||
|
||
class UserState(BaseModel): | ||
dialog_skill_id: str = "" | ||
is_waiting: bool = False | ||
|
||
class PublicUser(BaseModel): | ||
session: SessionConfigs = SessionConfigs() | ||
settings: UserSettings = UserSettings() | ||
state: UserState = UserState() | ||
|
||
class User(PublicUser): | ||
token: str | ||
|
||
class Skill(BaseModel): | ||
zip: str # b64 | ||
author: Author | ||
name: str | ||
|
||
class SkillInstance(BaseModel): | ||
skill: Skill | ||
state: str # b64 | ||
user_id: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from distutils.core import setup | ||
|
||
setup(name='kadia_common', | ||
version='0.0.1', | ||
description='The common code for Kadia voice assistant', | ||
author='Andrew Ishutin', | ||
author_email='hazmozavr@gmail.com', | ||
url='https://github.com/kadia-iva/kadia', | ||
packages=['kadia-common'], | ||
install_requires=[ | ||
'pydantic' | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fastapi | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``` | ||
uvicorn run:app --port 8080 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fastapi | ||
-f https://download.pytorch.org/whl/torch_stable.html | ||
torch==1.5.1+cpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from fastapi import FastAPI, WebSocket, Body | ||
from fastapi.responses import HTMLResponse | ||
from schemes import * | ||
import requests | ||
import json | ||
import time | ||
import os | ||
import string | ||
import logging | ||
|
||
mask = '[MASK]' | ||
digits = "0123456789" | ||
punctuation = string.punctuation + '’“”’—‘' + '–' | ||
|
||
""" | ||
Useful links: | ||
!!!Dataset instructions: https://www.weak-learner.com/blog/2019/12/27/ontonotes-5/ | ||
!!!Training instruction: https://huggingface.co/transformers/v2.2.0/examples.html#training | ||
DeepPavlov configs: https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/configs/ner/ner_ontonotes_bert.json | ||
Example: https://github.com/flairNLP/flair | ||
""" | ||
|
||
def char_is_emoji(character): | ||
return character in emoji.UNICODE_EMOJI | ||
|
||
def parse_to_words(text): | ||
text = text.lower() | ||
words = [] | ||
words_indexes = [] | ||
current = [] | ||
for i, el in enumerate(text + ' '): | ||
if el.isalpha(): | ||
current.append(el) | ||
elif el in digits: | ||
if len(current) != 0 and not current[-1] in digits: | ||
words.append(''.join(current)) | ||
words_indexes.append([i - len(current), i - 1]) | ||
current = [] | ||
current.append(el) | ||
elif el.isspace(): | ||
if len(current) != 0: | ||
words.append(''.join(current)) | ||
words_indexes.append([i - len(current), i - 1]) | ||
current = [] | ||
elif el in punctuation: # commas, dots, slashes | ||
if len(current) != 0: | ||
words.append(''.join(current)) | ||
words_indexes.append([i - len(current), i - 1]) | ||
current = [] | ||
words.append(el) | ||
words_indexes.append([i, i]) | ||
elif char_is_emoji(el): # emoji | ||
words.append('[UNK]') | ||
words_indexes.append([i, i]) | ||
else: | ||
logging.warning(f"Warning! Strange char {el}") | ||
return words, words_indexes | ||
|
||
def do_truecase(text): | ||
""" | ||
truecase text https://pypi.org/project/truecase/ | ||
source: https://arxiv.org/pdf/1903.11222.pdf | ||
""" | ||
pass | ||
|
||
def do_ner(text): | ||
"""use distilbert-base-cased""" | ||
pass | ||
|
||
def do_parse(text, entities): | ||
"""parse text to tokens. Entity must be a single token""" | ||
pass | ||
|
||
app = FastAPI() | ||
|
||
@app.post("/") # add more decorators | ||
def reply(text: str = Body(..., embed=True)): | ||
do_truecase() | ||
do_ner() | ||
do_parse() | ||
speech = Speech(...) | ||
return speech.as_dict() | ||
|
||
@app.post("/postprocess") # add more decorators | ||
def reply(text: str = Body(..., embed=True)): | ||
do_parse() | ||
speech = Speech(...) | ||
return speech.as_dict() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``` | ||
uvicorn run:app --port 8080 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fastapi | ||
-f https://download.pytorch.org/whl/torch_stable.html | ||
torch==1.5.1+cpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from fastapi import FastAPI, WebSocket, Body | ||
from fastapi.responses import HTMLResponse | ||
from schemes import * | ||
import requests | ||
import json | ||
import time | ||
import os | ||
import string | ||
import logging | ||
|
||
app = FastAPI() | ||
|
||
@app.post("/") # add more decorators | ||
def reply(text: str = Body(..., embed=True)): | ||
do_truecase() | ||
do_ner() | ||
do_parse() | ||
speech = Speech(...) | ||
return speech.as_dict() |
Oops, something went wrong.