clonely updates

This commit is contained in:
George Kasparyants
2024-08-06 16:13:23 +03:00
parent 5176e3d664
commit d1d4e68458
4 changed files with 218 additions and 46 deletions

View File

@@ -1,6 +1,12 @@
import json
import sys
import re
import spacy
# Load the language model
nlp = spacy.load("en_core_web_lg")
import sys
from time import sleep, time
import logging
from collections import defaultdict
@@ -9,6 +15,11 @@ from flask import redirect
import argparse
import base64
import pandas as pd
import openai, numpy as np
openai.api_key = "sk-proj-GaouEG2QuAcfAr1an2uBT3BlbkFJaIh0XVFXWrYQpJazlbeO"
# from openai.embeddings_utils import get_embedding, cosine_similarity
from flask import send_file, Response, request, jsonify
from flask_socketio import emit
from piedemo.fields.ajax_group import AjaxChatField, AjaxGroup
@@ -44,9 +55,14 @@ from tqdm import tqdm
from aihandler import AIHandler
from aihandler_stream import AIHandlerStream
from aihandler_new import AIHandlerNewStream
from pieinfer import PieInfer, render_video, construct_video
import torch
from TTS.api import TTS
sys.path.append("/home/ubuntu/repo/slavaBIM")
from pages.demo import DemoPage
logging.getLogger('socketio').setLevel(logging.ERROR)
logging.getLogger('engineio').setLevel(logging.ERROR)
@@ -133,6 +149,7 @@ class MainPage(Page):
self.r = redis.Redis(host='localhost', port=6379, decode_responses=True)
self.aihandler = AIHandler()
self.aihandler_stream = AIHandlerStream()
self.aihandler_new_stream = AIHandlerNewStream()
self.fields = Navigation(AjaxGroup("ChatGroup", VStack([
HStack([
@@ -263,8 +280,11 @@ web = Web({
"": "simple",
"simple": page,
"nice": page,
"secret_demo_of_c574d349": DemoPage(),
"secret_demo_of_c574dnew": DemoPage(load_new_model=True)
}, use_socketio_support=True)
web.add_assets_directory("IFC",
"/home/ubuntu/repo/slavaBIM/data/IFC")
host = '0.0.0.0'
port = 8011
@@ -518,6 +538,150 @@ def perform_surgery(sid, duration=5):
sleep(max(0., duration - (t2 - t1)))
BODY_ANIMATION_DESCRIPTIONS = [
"Get on your knees",
"Show butt",
"Show ass",
"Pull back",
"Doggy style",
"Sit on ass",
"Spread legs",
"Show pussy",
"Missionary position",
"Let fuck",
"Lie on side",
"Show legs",
"Rest",
"Relax",
"Sleep",
"Stand up",
"Showcase yourself",
"Show yourself",
"Show your boobs",
"Touch your boobs",
"Make a blowjob",
"On your knees",
"Sit on the dildo",
"Kiss my ass",
"Be on top"
]
resp = page.aihandler_stream.ai.embeddings.create(input=BODY_ANIMATION_DESCRIPTIONS,
model="text-embedding-3-small")
BODY_ANIMATION_EMBEDDINGS = np.array(list(map(lambda x: x.embedding,
resp.data)))
def to_back_view(sid):
emit("io_set_view",
[{"type": "back"}],
sid=sid)
def to_front_view(sid):
emit("io_set_view",
[{"type": "front"}],
sid=sid)
def to_up_to_down_view(sid):
emit("io_set_view",
[{"type": "up_to_down"}],
sid=sid)
@io.on("io_set_text_body")
def io_set_text_body(data):
data = json.loads(data)
data = data[0]
sid = None
print(data, file=sys.stderr)
if "text" not in data:
emit("io_error", {"message": "Text not found"},
to=sid)
return
text = data["text"]
user_id = data.get('user_id')
print(user_id)
emb = page.aihandler_stream.ai.embeddings.create(input=[text],
model="text-embedding-3-small")
idx = int(np.argmax(np.sum(np.array([emb.data[0].embedding]) * BODY_ANIMATION_EMBEDDINGS, axis=-1)))
animations_durations = {
1: 13,
2: 9.33,
3: 10.5,
4: 7.52,
5: 10,
}
print("Text: ", text, "\n",
"Detected:", BODY_ANIMATION_DESCRIPTIONS[idx], "\n",
"Index: ", idx, "\n")
# to_body_view(sid)
if 1 + idx // 5 == 1:
to_back_view(sid)
elif 1 + idx // 5 == 3:
to_up_to_down_view(sid)
else:
to_front_view(sid)
emit("io_set_body_animation",
[{
"index": 1 + idx // 5,
"timestamp": 0
}],
to=sid)
"""
start_speaking(text,
user_id=user_id,
sid=sid)
"""
sleep(animations_durations[1 + idx // 5] // 2)
to_front_view(sid)
sleep(animations_durations[1 + idx // 5] // 2)
emit("io_finish", {}, to=sid)
def start_speaking(text, user_id, sid):
TEXTS[user_id].append({
"id": "user",
"text": text
})
voice = SPEAKER.get(user_id, "voice1")
if sid not in head_memories:
head_memories[sid] = get_head_memory()
head_memory = head_memories[sid]
# output_texts = [page.aihandler(text)['text']]
output_texts = page.aihandler_stream(text)
# output_texts = page.aihandler_new_stream(text)
bot_text = ""
for output_text in output_texts:
sign = [2 * (random.random() > 0.5) - 1
for _ in range(8)]
head_memory = perform_on_text(output_text, sid, head_memory,
sign=sign,
voice=voice)
bot_text += " " + output_text
print("SURGERY STARTED!")
# perform_surgery(sid)
print("SURGERY ENDED!")
TEXTS[user_id].append({
"id": "bot",
"text": bot_text
})
@io.on("io_set_text")
def io_set_text(data):
data = json.loads(data)
@@ -537,32 +701,9 @@ def io_set_text(data):
return"""
user_id = data.get('user_id')
print(user_id)
TEXTS[user_id].append({
"id": "user",
"text": text
})
voice = SPEAKER.get(user_id, "voice1")
if sid not in head_memories:
head_memories[sid] = get_head_memory()
head_memory = head_memories[sid]
# output_texts = [page.aihandler(text)['text']]
output_texts = page.aihandler_stream(text)
bot_text = ""
for output_text in output_texts:
sign = [2 * (random.random() > 0.5) - 1
for _ in range(8)]
head_memory = perform_on_text(output_text, sid, head_memory,
sign=sign,
voice=voice)
bot_text += " " + output_text
print("SURGERY STARTED!")
# perform_surgery(sid)
print("SURGERY ENDED!")
TEXTS[user_id].append({
"id": "bot",
"text": bot_text
})
start_speaking(text,
user_id=user_id,
sid=sid)
emit("io_finish", {}, to=sid)