Skip to content

Commit

Permalink
v5.0
Browse files Browse the repository at this point in the history
- Improved general stability
- Rewritten UI
- Refactored logic from scratch
- Client and Server split
- Moved to clear HTML implementation
- Dymanic server config
- Faster loading
- Less VRAM usage
- Faster model loading
  • Loading branch information
yukiarimo committed Nov 11, 2023
1 parent fd7c842 commit 64b4d27
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 1,191 deletions.
4 changes: 2 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from transformers import pipeline
import sys

if os.path.exists("config.json"):
with open("config.json", 'r') as file:
if os.path.exists("static/config.json"):
with open("static/config.json", 'r') as file:
config = json.load(file)

classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
Expand Down
144 changes: 87 additions & 57 deletions templates/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,62 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar" content="#99c189">
<meta name="theme-color" content="#99c189" />
<link rel="icon" href="static/img/favicon.ico" type="image/x-icon">
<meta name="referrer" content="no-referrer-when-downgrade"> <!-- For privacy and security -->

<title>Yuna</title>

<link rel="stylesheet" href="/static/css/index.css">
<link rel="stylesheet" href="/static/css/kawai.css">
<link href="/static/fonts/kawai-font.woff" rel="stylesheet">
<link href="/static/manifest.json" rel="manifest" crossorigin="use-credentials" />
<script src="/static/js/index.js" defer></script>
<script src="/static/js/kawai.js" defer></script>
<link rel="stylesheet" href="static/css/index.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/yukiarimo/kawai-framework@main/assets/css/kawai.css">
<script src="https://cdn.jsdelivr.net/gh/yukiarimo/kawai-framework@main/assets/js/kawai.js" defer></script>
<link href="static/fonts/kawai-font.woff" rel="stylesheet">
<link href="/manifest.json" rel="manifest" crossorigin="use-credentials" />
<script src="static/js/index.js" defer></script>

<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw.js').then(
function (registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration
.scope);
},
function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
</head>

<body>
<div class="sidebar-o desktop-only" id="sidebar">
<div class="sidebar-o hideside" id="sidebar">
<div class="coll-lo v-coll" style="background: none;">
<img src="/static/img/yuna.png" alt="Yuna" class="block-image">
<div class="block-text la">Yuna</div>
<div class="block-text la">Menu</div>
</div>

<div class="side-tab-block">x
<div class="side-tab-block-e" onclick="SideSwitch();">Side</div>
<div class="side-tab-block">
<div class="side-tab-block-e" onclick="OpenTab('1')">Chat</div>
<div class="side-tab-block-e" onclick="OpenTab('2')">Call</div>
<div class="side-tab-block-e" onclick="OpenTab('3')">Settings</div>
<div class="side-tab-block-e" onclick="OpenTab('3')">Mode</div>
</div>
</div>

<div class="block-o center">
<div class="tab-o tab-o-default" id="1">
<div class="topbar-o">
<div class="block-button" id="toggleButtonSide" onclick="SideSwitch();">Side</div>
<div class="block-button" id="toggleButtonSide" onclick="toggleSidebar();">Side</div>
<div class="top-tab-block">
<div class="top-tab-block-e block-text">
<img src="/static/img/yuna.png" alt="Yuna" class="block-image">
<img src="static/img/yuna.png" alt="Yuna" class="block-image">
</div>
<div class="top-tab-block-e block-text">
<h1 class="la block-text">Yuna</h1>
</div>
</div>
<div class="la block-text">⚙️</div>
<div class="la block-text" id="settingsButton">⚙️</div>
</div>

<div class="coll-lo">
Expand All @@ -64,38 +80,18 @@ <h1 class="la block-text">Yuna</h1>
<div class="coll-lo">
<form class="block-card el-9 h-coll" onsubmit="handleSubmit(event)">
<textarea id="input_text" placeholder="Talk to Yuna..."></textarea>
<button type="submit" class="block-button">Send</button>
<button type="submit" class="block-button">💬</button>
<button type="button" class="block-button" onclick="OpenPopup('options')"></button>
</form>
</div>

<div class="coll-lo">
<div class="block-card el-9 h-coll">
<button type="button" class="block-button" onclick="editHistory()">📝</button>
<button type="button" class="block-button" onclick="loadSelectedHistory()"></button>
<button type="button" class="block-button" onclick="downloadHistory()">⬇️</button>
<button type="button" class="block-button" onclick="location.reload();">🔄</button>
<button type="button" class="block-button" onclick="scrollMsg();">👇</button>
<button type="button" class="block-button" onclick="muteAudio()">🔇</button>
<button class="block-button" aria-label="History"><select id="history-select"
onchange="loadSelectedHistory()">📁</select></button>
</div>
</div>

<details class="coll-lo">
<div class="block-card el-9 h-coll">
<textarea id="codeInput" rows="5" cols="40" placeholder="Enter JavaScript"></textarea>
<button type="button" class="block-button" id="executeButton">Run</button>
<textarea id="consoleOutput" rows="10" cols="40" readonly=""></textarea>
</div>
</details>
</div>

<div class="tab-o" id="2">
<div class="topbar-o">
<div class="block-button" id="toggleButtonSide" onclick="SideSwitch();">Side</div>
<div class="block-button" id="toggleButtonSide" onclick="toggleSidebar();">Side</div>
<div class="top-tab-block">
<div class="top-tab-block-e block-text">
<img src="/static/img/yuna.png" alt="Yuna" class="block-image">
<img src="static/img/yuna.png" alt="Yuna" class="block-image">
</div>
<div class="top-tab-block-e block-text">
<h1 class="la block-text">Yuna</h1>
Expand All @@ -106,12 +102,12 @@ <h1 class="la block-text">Yuna</h1>

<div class="coll-lo">
<audio id="backgroundMusic">
<source src="/static/audio/output.mp3" type="audio/mp3">
<source src="static/audio/output.mp3" type="audio/mp3">
</audio>

<div class="participant el-9 block-card">
<div class="block-text la">Call</div>
<img src="/static/img/yuna-full.png" alt="Yuna Participant" style="border-radius: 20px;">
<img src="static/img/yuna-full.png" alt="Yuna Participant" style="border-radius: 20px;">
<video id="localVideo" playsinline autoplay muted class="draggable-video"></video>
<div class="controls">
<button class="block-button" id="camera-off">📷</button>
Expand All @@ -128,10 +124,10 @@ <h1 class="la block-text">Yuna</h1>

<div class="tab-o" id="3">
<div class="topbar-o">
<div class="block-button" id="toggleButtonSide" onclick="SideSwitch();">Side</div>
<div class="block-button" id="toggleButtonSide" onclick="toggleSidebar();">Side</div>
<div class="top-tab-block">
<div class="top-tab-block-e block-text">
<img src="/static/img/yuna.png" alt="Yuna" class="block-image">
<img src="static/img/yuna.png" alt="Yuna" class="block-image">
</div>
<div class="top-tab-block-e block-text">
<h1 class="la block-text">Yuna</h1>
Expand All @@ -142,27 +138,61 @@ <h1 class="la block-text">Yuna</h1>

<div class="coll-lo">
<div class="block-card el-9">
<h1>Settings</h1>
<h1>Modes</h1>
<div class="block-card">
<div class="block-text lc">Dark Mode</div>
<div class="block-toggle"></div>
<div class="block-text lc">Story writting</div>
</div>
</div>
</div>
</div>
</div>

<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/static/js/sw.js')
.then((registration) => {
console.log('Service Worker registered with scope:', registration.scope);
})
.catch((error) => {
console.error('Service Worker registration failed:', error);
});
}
</script>
<div class="block-popup" id="settings">
<div class="block-button-close" onclick="PopupClose();">X</div>
<div class="coll-lo">
<div class="block-card el-9">
<h1>Mode</h1>
<div class="block-toggle"></div>
</div>
</div>

<div class="coll-lo">
<div class="block-card el-9">
<div id="parameter-container">
<!-- Dynamic HTML elements will be added here -->
</div>
<button id="save-button">Save Parameters to Local Storage</button>
</div>
</div>

<div class="coll-lo">
<details class="coll-lo">
<div class="block-card el-9 h-coll">
<textarea id="codeInput" rows="5" cols="40" placeholder="Enter JavaScript"></textarea>
<button type="button" class="block-button" id="executeButton">Run</button>
<textarea id="consoleOutput" rows="10" cols="40" readonly=""></textarea>
</div>
</details>
</div>
</div>

<div class="block-popup" id="options">
<div class="block-button-close" onclick="PopupClose();">X</div>
<div class="coll-lo">
<div class="block-list el-9 v-coll">
<div class="block-list-e" onclick="editHistory()">✍️ Edit</div>
<div class="block-list-e" onclick="loadSelectedHistory()">👇 Load</div>
<div class="block-list-e" onclick="downloadHistory()">⬇️ Download</div>
<div class="block-list-e" onclick="location.reload();">🔄 Refresh</div>
<div class="block-list-e" onclick="scrollMsg();">📜 Scroll</div>
<div class="block-list-e" onclick="muteAudio()">📢 Mute</div>
<label for="history-select">History</label>
<button class="block-button" aria-label="History">
<select id="history-select" onchange="loadSelectedHistory()">📁</select>
</button>
</div>
</div>
</div>

<script>
// Function to execute JavaScript code entered by the user
Expand Down
14 changes: 5 additions & 9 deletions index.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from flask import Flask, request, render_template, jsonify, send_from_directory
from flask import Flask, request, jsonify
import shutil
import subprocess
from generate import generate # Import the generate function from generate.py
import os
import json
import re
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

if os.path.exists("config.json"):
with open("config.json", 'r') as file:
if os.path.exists("static/config.json"):
with open("static/config.json", 'r') as file:
config = json.load(file)

# Function to load chat history from the JSON file
Expand All @@ -25,11 +26,6 @@ def save_chat_history(chat_history, chat):
with open(config["history"] + chat, 'w') as file:
json.dump(chat_history, file)

# Your existing route for rendering the HTML page
@app.route('/', methods=['GET', 'POST'])
def index():
return render_template('index.html')

# New route for sending and receiving messages
@app.route('/send_message', methods=['POST'])
def send_message():
Expand Down
24 changes: 24 additions & 0 deletions lib/c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from ctransformers import AutoModelForCausalLM

llm = AutoModelForCausalLM.from_pretrained(
"lib/yunacpp/models/pygmalion-2-7b.Q5_K_M.gguf",
model_type='llama2',
top_k=40,
top_p=0.1,
temperature=0.7,
repetition_penalty=1.18,
last_n_tokens=64,
seed=123,
batch_size=64,
context_length=8192,
max_new_tokens=300,
gpu_layers=1
)

while True:
test = input("YUKI: ")

print("Yuna: ", end="")
for text in llm("Yuki: " + test + "\nYuna:", stream=True):
print(text, end="", flush=True)
print()
Binary file modified lib/yunacpp/build-yuna.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions static/manifest.json → manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
"name": "Yuna",
"short_name": "Yuna",
"description": "Yuna AI - your personal AI girlfriend",
"lang": "en",
"start_url": "/",
"display": "standalone",
"background_color": "#99c189",
"theme_color": "#99c189",
"icons": [{
"src": "/static/img/yuna.png",
"src": "static/img/yuna.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/static/img/yuna.png",
"src": "static/img/yuna.png",
"sizes": "512x512",
"type": "image/png"
}
Expand Down
10 changes: 6 additions & 4 deletions config.json → static/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"emotions": false,
"request": {
"n": 1,
"max_context_length": 1280,
"max_length": 128,
"max_context_length": 1024,
"max_length": 256,
"rep_pen": 1.1,
"temperature": 0.65,
"temperature": 0.7,
"top_p": 1,
"top_k": 0,
"top_a": 0,
Expand All @@ -19,5 +19,7 @@
"use_default_badwordsids": false
},
"port": 4848,
"history": "static/db/"
"history": "static/db/",
"manes": ["Yuki", "Yuna"],
"server": "http://localhost:4848/"
}
20 changes: 18 additions & 2 deletions static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
height: 100vh;
}

.block-popup {
display: flex !important;
.block-button-close {
position: relative !important;
}

#parameter-container {
display: flex;
flex-direction: column;
padding: 2%;
}

.topbar-o {
Expand Down Expand Up @@ -52,6 +58,7 @@ img {
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
/* Add shadow for a modern look */
overflow-x: hidden !important;
max-height: calc(100vh - 500px) !important;
}

/* Individual chat message styles */
Expand Down Expand Up @@ -155,8 +162,17 @@ img {
padding: 10px;
}

.uside {
width: auto !important;
float: none !important;
}

@media (max-width : 428px) {
.participant>img {
width: 100% !important;
}

#message-container {
max-height: calc(100vh - 300px) !important;
}
}
Loading

0 comments on commit 64b4d27

Please sign in to comment.