Skip to content

Commit

Permalink
Little Directory Refactoring and Audiobook Improvements
Browse files Browse the repository at this point in the history
- `lib/models/` moved to `lib/utils/models/`
- Audiobook Tab in Creator Studio now supports projects
- Necessary files were added
- Messed up some shit
  • Loading branch information
yukiarimo committed Nov 10, 2024
1 parent f505221 commit f64d35f
Show file tree
Hide file tree
Showing 30 changed files with 1,614 additions and 326 deletions.
26 changes: 13 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
__pycache__/
!static/audio/README.md
!static/audio/audiobooks/README.md
!static/audio/sfx/*
!static/text/README.md
!static/img/call/image_template.jpg
!lib/utils/models/agi/README.md
!lib/utils/models/agi/audio/README.md
!lib/utils/models/agi/miru/README.md
!lib/utils/models/agi/voice/README.md
!lib/utils/models/yuna/README.md
!lib/utils/tests/README.md
!db/history/README.md
lib/utils/tests/*
db/history/*
!db/history/README.md
static/audio/output.aiff
static/audio/output.mp3
static/text/*
!static/text/README.md
static/img/call/*
!static/img/call/image_template.jpg
static/img/art/*
!static/img/art/art_template.png
static/audio/*
!static/audio/README.md
!static/audio/sfx/*
lib/models/*
!lib/models/agi/README.md
!lib/models/agi/audio/README.md
!lib/models/agi/miru/README.md
!lib/models/agi/voice/README.md
!lib/models/yuna/README.md
lib/utils/models/*
llama.log
.DS_Store
9 changes: 0 additions & 9 deletions .vscode/settings.json

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ Controls server-side operations and model settings:
- `yuna_text_mode`: Text processing mode (native/koboldcpp/lmstudio)
- `yuna_audio_mode`: Audio processing mode (native/siri/siri-pv/11labs)
- `yuna_reference_audio`: Voice reference file for audio processing
- `output_audio_format`: Audio output format (wav/ogg/mp3/aiff)

#### Settings Configuration Block
Manages user preferences and features:
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<meta name="theme-color" content="#212529">
<link rel="canonical" href="http://www.yuna-ai.live/">
<meta property="og:url" content="http://www.yuna-ai.live/">
<meta property="og:description" content="Your virtual AI girlfriend">
<meta property="og:description" content="Your Private Companion">
<meta name="twitter:image" content="http://www.yuna-ai.live/static/img/yuna-ai.png">
<meta name="twitter:title" content="Yuna AI">
<meta property="og:image" content="http://www.yuna-ai.live/static/img/yuna-ai.png">
<meta name="description" content="Your virtual AI girlfriend">
<meta name="description" content="Your Private Companion">
<meta property="og:type" content="website">
<meta property="og:title" content="Yuna AI">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:description" content="Your virtual AI girlfriend">
<meta name="twitter:description" content="Your Private Companion">
<script type="application/ld+json">
{
"@context": "http://schema.org",
Expand Down
88 changes: 87 additions & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
from flask import Flask, request, jsonify, send_from_directory, redirect, url_for, make_response
from flask_login import LoginManager, UserMixin, login_required, logout_user, login_user, current_user, login_manager
from lib.generate import ChatGenerator, ChatHistoryManager, get_config
from lib.router import generate_audiobook, handle_history_request, handle_image_request, handle_message_request, handle_audio_request, services, handle_search_request, handle_textfile_request
from lib.router import create_project_directory, generate_audiobook, handle_history_request, handle_image_request, handle_message_request, handle_audio_request, services, handle_search_request, handle_textfile_request, merge_audiobook
from flask_cors import CORS
import json
import os
from itsdangerous import URLSafeTimedSerializer
from flask_compress import Compress
import pywebpush
from cryptography.hazmat.primitives import serialization

vapid = pywebpush.Vapid()
vapid.generate_keys()

public_key = vapid.public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
).decode('utf-8')

private_key = vapid.private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption()
).decode('utf-8')

print(f"Public key: {public_key}")
print(f"Private key: {private_key}")


config = get_config()
secret_key = config['security']['secret_key']
Expand All @@ -28,6 +48,11 @@ def __init__(self):
'text/javascript',
'application/x-javascript'
]
self.VAPID_PRIVATE_KEY = vapid.private_key
self.VAPID_PUBLIC_KEY = vapid.public_key
self.VAPID_CLAIMS = {
"sub": "mailto:[email protected]"
}
self.app.config['COMPRESS_LEVEL'] = 9 # Gzip compression level (1-9)
self.app.config['COMPRESS_MIN_SIZE'] = 0
Compress(self.app)
Expand All @@ -36,6 +61,8 @@ def __init__(self):
login_manager.user_loader(self.user_loader)
CORS(self.app, resources={r"/*": {"origins": "*"}})
self.configure_routes()
self.app.route('/subscribe', methods=['POST'])(self.subscribe)
self.app.route('/send-notification', methods=['POST'])(self.send_notification)
self.chat_generator = ChatGenerator(config)
self.chat_history_manager = ChatHistoryManager(config)
self.app.errorhandler(404)(self.page_not_found)
Expand Down Expand Up @@ -99,10 +126,69 @@ def configure_routes(self):
self.app.route('/image', methods=['POST'], endpoint='image')(lambda: handle_image_request(self.chat_history_manager, config))
self.app.route('/audio', methods=['GET', 'POST'], endpoint='audio')(lambda: handle_audio_request())
self.app.route('/generate_audiobook', methods=['POST'], endpoint='generate_audiobook')(lambda: generate_audiobook())
self.app.route('/merge_audiobook', methods=['POST'], endpoint='merge_audiobook')(lambda: merge_audiobook())
self.app.route('/create_project_directory', methods=['POST'], endpoint='create_project')(lambda: create_project_directory())
self.app.route('/analyze', methods=['POST'], endpoint='textfile')(lambda: handle_textfile_request(self.chat_generator))
self.app.route('/logout', methods=['GET'])(self.logout)
self.app.route('/search', methods=['POST'], endpoint='search')(lambda: handle_search_request())

@staticmethod
def pem_to_key(pem_str):
# Remove headers and newlines
lines = pem_str.replace('-----BEGIN PRIVATE KEY-----', '')
lines = lines.replace('-----END PRIVATE KEY-----', '')
lines = lines.replace('-----BEGIN PUBLIC KEY-----', '')
lines = lines.replace('-----END PUBLIC KEY-----', '')
return ''.join(lines.split('\n')).strip()

def subscribe(self):
try:
subscription = request.json
print("Received subscription:", subscription) # Debug log

user_id = current_user.get_id() if current_user.is_authenticated else 'anonymous'
subscription_path = os.path.join('db', 'subscriptions', f'{user_id}.json')

os.makedirs(os.path.dirname(subscription_path), exist_ok=True)

with open(subscription_path, 'w') as f:
json.dump(subscription, f)

return jsonify({'success': True, 'message': 'Subscription saved'}), 200

except Exception as e:
print(f"Subscription error: {e}") # Debug log
return jsonify({'error': str(e)}), 500

def send_notification(self):
try:
subscription = request.json.get('subscription')
message = request.json.get('message', 'Hello from Yuna!')

print(f"Sending notification to subscription: {subscription}") # Debug log

payload = json.dumps({
'title': 'Yuna AI',
'body': message,
'icon': '/static/img/yuna-ai.png',
'badge': '/static/img/yuna-girl-head.webp'
})

response = pywebpush(
subscription_info=subscription,
data=payload,
vapid_private_key=self.VAPID_PRIVATE_KEY,
vapid_claims=self.VAPID_CLAIMS
)

print(f"Webpush response: {response}") # Debug log

return jsonify({'success': True, 'message': 'Notification sent'}), 200

except Exception as e:
print(f"Notification error: {e}") # Debug log
return jsonify({'error': str(e)}), 500

def custom_static(self, filename):
if not filename.startswith('static/') and not filename.startswith('/favicon.ico') and not filename.startswith('/manifest.json'):
filename = 'static/' + filename
Expand Down
14 changes: 7 additions & 7 deletions index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ install_all_agi_models() {
# Function to install Vision model
install_vision_model() {
echo "Installing Vision model..."
wget https://huggingface.co/yukiarimo/yuna-ai-vision-v2/resolve/main/yuna-ai-miru-v0.gguf -P lib/models/agi/miru/
wget https://huggingface.co/yukiarimo/yuna-ai-vision-v2/resolve/main/yuna-ai-miru-eye-v0.gguf -P lib/models/agi/miru/
wget https://huggingface.co/yukiarimo/yuna-ai-vision-v2/resolve/main/yuna-ai-miru-v0.gguf -P lib/utils/models/agi/miru/
wget https://huggingface.co/yukiarimo/yuna-ai-vision-v2/resolve/main/yuna-ai-miru-eye-v0.gguf -P lib/utils/models/agi/miru/
}

# Function to install Art model
install_art_model() {
echo "Installing Art model..."
echo "This is not implemented yet."
# wget https://huggingface.co/yukiarimo/anyloli/resolve/main/any_loli.safetensors -P lib/models/agi/art/
# wget https://huggingface.co/yukiarimo/anyloli/resolve/main/any_loli.safetensors -P lib/utils/models/agi/art/
}

# Function to install Himitsu model
Expand All @@ -193,7 +193,7 @@ install_talk_model() {
echo "Enter the Hugging Face model name (e.g., username/model): "
read model_name
echo "Installing Talk Model"
git clone https://huggingface.co/$model_name lib/models/agi/voice
git clone https://huggingface.co/$model_name lib/utils/models/agi/voice
}

# Function to install Yuna model
Expand All @@ -208,20 +208,20 @@ install_yuna_model() {

model_url="https://huggingface.co/yukiarimo/yuna-ai-${version}/resolve/main/yuna-ai-${version}-${size}.gguf"
echo "Installing Yuna model from $model_url..."
wget "$model_url" -P lib/models/yuna/
wget "$model_url" -P lib/utils/models/yuna/
}

# Function to clear models
clear_models() {
clear
echo "========== Clear Models Menu =========="
echo "This will delete all models inside 'lib/models/'."
echo "This will delete all models inside 'lib/utils/models/'."
read -p "Do you want to proceed? (y/n): " confirm_clear

case $confirm_clear in
[Yy])
echo "Clearing models..."
rm -rf lib/models/*
rm -rf lib/utils/models/*
echo "Models cleared."
;;
[Nn])
Expand Down
Loading

0 comments on commit f64d35f

Please sign in to comment.