Template refactor, task update
Banter no longer fails if AI offline. Refactoring of templates.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 556 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
body {
|
||||||
|
background-color: #01817F;
|
||||||
|
}
|
||||||
|
|
||||||
.window:not([role="tabpanel"]) {
|
.window:not([role="tabpanel"]) {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index:99;
|
z-index:99;
|
||||||
|
|||||||
+38
-30
@@ -1,46 +1,54 @@
|
|||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from .models import Track
|
from .models import Track
|
||||||
|
|
||||||
|
import os
|
||||||
import dotenv
|
import dotenv
|
||||||
|
|
||||||
import os
|
|
||||||
import requests
|
|
||||||
|
|
||||||
import time
|
|
||||||
import json
|
import json
|
||||||
from random import choice
|
from requests import get, post
|
||||||
|
from requests.exceptions import ConnectionError
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
UPDATE_FREQ = 10 # How often to save to database
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def get_banter(id):
|
def get_banter(id):
|
||||||
|
"""
|
||||||
|
Requests an AI model for some banter.
|
||||||
|
Currently expects an ollama instance to be running,
|
||||||
|
but might be possible to use OpenAI API in future.
|
||||||
|
"""
|
||||||
track = Track.objects.get(pk=id)
|
track = Track.objects.get(pk=id)
|
||||||
r = requests.post(
|
|
||||||
os.getenv('AI_ENDPOINT'),
|
|
||||||
json={
|
|
||||||
'model': os.getenv('AI_MODEL'),
|
|
||||||
'prompt': str(track)
|
|
||||||
},
|
|
||||||
stream=True
|
|
||||||
)
|
|
||||||
r.raise_for_status()
|
|
||||||
|
|
||||||
token = 0
|
try:
|
||||||
|
get(os.getenv('AI_ENDPOINT'))
|
||||||
|
except ConnectionError:
|
||||||
|
track.banter = "Error"
|
||||||
|
track.banter_done = True
|
||||||
|
track.save()
|
||||||
|
return f"{track}: AI endpoint not available."
|
||||||
|
|
||||||
for line in r.iter_lines():
|
try:
|
||||||
body = json.loads(line)
|
r = post(
|
||||||
response_part = body.get('response', '')
|
os.getenv('AI_ENDPOINT'),
|
||||||
token += 1
|
json={
|
||||||
track.banter += response_part
|
'model': os.getenv('AI_MODEL'),
|
||||||
|
'prompt': str(track)
|
||||||
|
},
|
||||||
|
stream=True
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
|
||||||
if 'error' in body:
|
for line in r.iter_lines():
|
||||||
raise Exception(body['error'])
|
body = json.loads(line)
|
||||||
|
if 'error' in body:
|
||||||
|
raise Exception(body['error'])
|
||||||
|
track.banter += body.get('response', '')
|
||||||
|
|
||||||
if body.get('done', False):
|
if body.get('done', False):
|
||||||
track.banter_done = True
|
track.banter_done = True
|
||||||
track.save()
|
track.save()
|
||||||
return body['context']
|
return f"{track}: {body['context']}"
|
||||||
elif token % UPDATE_FREQ == 0:
|
except Exception as e:
|
||||||
track.save()
|
track.banter_done = True
|
||||||
|
track.save()
|
||||||
|
return f"{track}: {e}"
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
|
{% load static %}
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{% load static %}
|
{% include "head.html" %}
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<script src="{% static 'js/htmx.min.js' %}" defer></script>
|
|
||||||
<script src="https://unpkg.com/interactjs"></script>
|
|
||||||
<link rel="stylesheet" href="https://unpkg.com/98.css" >
|
|
||||||
|
|
||||||
<link href="{% static 'style.css'%}" rel="stylesheet" type="text/css" />
|
|
||||||
<script src="https://open.spotify.com/embed/iframe-api/v1" async></script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' style="background:#01817F;">
|
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
|
||||||
<div class="window">
|
<div class="window" id="main-window">
|
||||||
<div class="title-bar">
|
<div class="title-bar">
|
||||||
<div class="title-bar-text">
|
<div class="title-bar-text">
|
||||||
{% block window-title %}{% endblock %}
|
{% block window-title %}{% endblock %}
|
||||||
@@ -42,14 +35,12 @@
|
|||||||
</div>
|
</div>
|
||||||
{% block clippy %}{% endblock %}
|
{% block clippy %}{% endblock %}
|
||||||
<script>
|
<script>
|
||||||
position = { x: 0, y: 0 }
|
position.get_pos(); // Gets position from localStorage
|
||||||
|
|
||||||
interact('.title-bar').draggable({
|
interact('.title-bar').draggable({
|
||||||
listeners: {
|
listeners: {
|
||||||
move (event) {
|
move (event) {
|
||||||
position.x += event.dx
|
position.x += event.dx
|
||||||
position.y += event.dy
|
position.y += event.dy
|
||||||
|
|
||||||
event.target.parentElement.style.transform =
|
event.target.parentElement.style.transform =
|
||||||
`translate(${position.x}px, ${position.y}px)`
|
`translate(${position.x}px, ${position.y}px)`
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% if body %}
|
||||||
<script>
|
<script>
|
||||||
function closeclippy(e) {
|
function closeclippy(e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
@@ -14,4 +15,4 @@
|
|||||||
<img src="{% static img %}" />
|
<img src="{% static img %}" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{% load static %}
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<script src="{% static 'js/htmx.min.js' %}" defer></script>
|
||||||
|
<script src="https://unpkg.com/interactjs"></script>
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/98.css" >
|
||||||
|
<link href="{% static 'style.css'%}" rel="stylesheet" type="text/css" />
|
||||||
|
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'apple-touch-icon.png' %}">
|
||||||
|
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'favicon-32x32.png' %}">
|
||||||
|
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'favicon-16x16.png' %}">
|
||||||
|
<link rel="manifest" href="/site.webmanifest">
|
||||||
|
<script src="https://open.spotify.com/embed/iframe-api/v1" async></script>
|
||||||
|
<title>HD Muzak: {{ request.path }}</title>
|
||||||
|
<script>
|
||||||
|
//Global position object for cross-page window positioning
|
||||||
|
position = {
|
||||||
|
set x(val) {
|
||||||
|
this._x = val
|
||||||
|
localStorage.setItem("position", JSON.stringify({x: val, y: this._y}));
|
||||||
|
},
|
||||||
|
set y(val) {
|
||||||
|
this._y = val
|
||||||
|
localStorage.setItem("position", JSON.stringify({x: this._x, y: val}));
|
||||||
|
},
|
||||||
|
get x() { return this._x },
|
||||||
|
get y() { return this._y },
|
||||||
|
_x: 0, _y: 0,
|
||||||
|
get_pos() {
|
||||||
|
stored_position = JSON.parse(localStorage.getItem("position"));
|
||||||
|
if (stored_position != null) {
|
||||||
|
position.x = stored_position.x
|
||||||
|
position.y = stored_position.y
|
||||||
|
document.getElementById("main-window").style.transform =
|
||||||
|
`translate(${position.x}px, ${position.y}px)`
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem("position")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
+1
-1
@@ -11,7 +11,7 @@ def from_json(cls, json):
|
|||||||
|
|
||||||
def get_unvoted(user):
|
def get_unvoted(user):
|
||||||
votes = set(Vote.objects.filter(user=user).values_list('track_id', flat=True))
|
votes = set(Vote.objects.filter(user=user).values_list('track_id', flat=True))
|
||||||
tracks = set(Track.objects.values_list('pk', flat=True))
|
tracks = set(Track.objects.filter(banter_done=True).values_list('pk', flat=True))
|
||||||
seed(user.username)
|
seed(user.username)
|
||||||
try:
|
try:
|
||||||
random_track = choice(list(tracks - votes))
|
random_track = choice(list(tracks - votes))
|
||||||
|
|||||||
Reference in New Issue
Block a user