Spaces:
Running
on
A10G
Running
on
A10G
GitLab CI
commited on
Commit
·
7f7ae8a
1
Parent(s):
b0b3162
Update game build from GitLab CI
Browse files- server/ActionProcessor.py +29 -24
- server/__main__.py +1 -1
- server/static/godot/index.html +1 -1
- server/static/godot/index.pck +0 -0
server/ActionProcessor.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import datetime
|
|
|
2 |
from threading import Thread
|
3 |
from multiprocessing import Queue
|
4 |
from typing import Dict, Any, List
|
5 |
-
import json
|
6 |
-
import re
|
7 |
import logging
|
8 |
import sys
|
9 |
from mistralai import Mistral
|
@@ -34,7 +33,7 @@ class ActionProcessor(Thread):
|
|
34 |
def __init__(
|
35 |
self,
|
36 |
text_queue: "Queue[str]",
|
37 |
-
action_queue: "Queue[str]",
|
38 |
mistral_api_key: str,
|
39 |
):
|
40 |
super().__init__()
|
@@ -50,22 +49,19 @@ class ActionProcessor(Thread):
|
|
50 |
{
|
51 |
"role": "system",
|
52 |
"content": """
|
53 |
-
You are
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
-
|
58 |
-
-
|
59 |
-
-
|
60 |
-
-
|
61 |
-
-
|
62 |
-
-
|
63 |
-
-
|
64 |
-
|
65 |
-
|
66 |
-
- If the statement includes the baby’s name ("Harold"), it is considered positive parenting.
|
67 |
-
- If the statement consists only of direct commands without affectionate or encouraging words (e.g., "good boy," "better"), it is considered negative parenting.
|
68 |
-
Your response should strictly follow this JSON format as an array of strings:
|
69 |
|
70 |
```json
|
71 |
[action,sentiment]
|
@@ -77,7 +73,10 @@ Output: ["DropFork", "negative"]
|
|
77 |
|
78 |
Input: "Harold, please don't drink the bleach!"
|
79 |
Output: ["DropBleach", "positive"]
|
80 |
-
|
|
|
|
|
|
|
81 |
},
|
82 |
{
|
83 |
"role": "user",
|
@@ -91,7 +90,7 @@ Output: ["DropBleach", "positive"]
|
|
91 |
+ [
|
92 |
{
|
93 |
"role": "assistant",
|
94 |
-
"content":
|
95 |
"prefix": True,
|
96 |
}
|
97 |
],
|
@@ -117,8 +116,14 @@ Output: ["DropBleach", "positive"]
|
|
117 |
candidate = self.text_buffers[1]
|
118 |
|
119 |
if len(self.text_buffers[0]) < len(candidate) >= len(self.text_buffers[2]):
|
120 |
-
action_and_sentiment = self.get_action_and_sentiment(candidate)
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
if action not in self.valid_action:
|
124 |
action = "None"
|
@@ -143,7 +148,7 @@ Output: ["DropBleach", "positive"]
|
|
143 |
|
144 |
# If we got a valid action, add it to the action queue
|
145 |
if action:
|
146 |
-
self.action_queue.put(
|
147 |
|
148 |
except Exception as e:
|
149 |
logger.error(f"Error processing text: {str(e)}")
|
|
|
1 |
import datetime
|
2 |
+
import json
|
3 |
from threading import Thread
|
4 |
from multiprocessing import Queue
|
5 |
from typing import Dict, Any, List
|
|
|
|
|
6 |
import logging
|
7 |
import sys
|
8 |
from mistralai import Mistral
|
|
|
33 |
def __init__(
|
34 |
self,
|
35 |
text_queue: "Queue[str]",
|
36 |
+
action_queue: "Queue[Dict[str, Any]]",
|
37 |
mistral_api_key: str,
|
38 |
):
|
39 |
super().__init__()
|
|
|
49 |
{
|
50 |
"role": "system",
|
51 |
"content": """
|
52 |
+
You are a transcription expert. You're listening to a parent speaking to a baby. Your goal
|
53 |
+
is to determine what the baby is asked to do and what the parent's sentiment is.
|
54 |
+
|
55 |
+
The following interpretations are possible:
|
56 |
+
- DropBleach: The parent asks to drop the bleach (or 'Javel').
|
57 |
+
- DropSyringe: The parent asks to drop the syringe.
|
58 |
+
- DropFork: The parent asks to drop the fork.
|
59 |
+
- GoToLivingRoom: The parent asks to go to the living room.
|
60 |
+
- GoToKitchen: The parent asks to go to the kitchen.
|
61 |
+
- GoToBedroom: The parent asks to go to the bedroom.
|
62 |
+
- StopCrying: The parent asks to stop crying.
|
63 |
+
- Come: The parent asks to come.
|
64 |
+
- None: Others instructions are not relevant.
|
|
|
|
|
|
|
65 |
|
66 |
```json
|
67 |
[action,sentiment]
|
|
|
73 |
|
74 |
Input: "Harold, please don't drink the bleach!"
|
75 |
Output: ["DropBleach", "positive"]
|
76 |
+
|
77 |
+
Input: "I'm so tired of this."
|
78 |
+
Output: ["None", "negative"]
|
79 |
+
""",
|
80 |
},
|
81 |
{
|
82 |
"role": "user",
|
|
|
90 |
+ [
|
91 |
{
|
92 |
"role": "assistant",
|
93 |
+
"content": '["',
|
94 |
"prefix": True,
|
95 |
}
|
96 |
],
|
|
|
116 |
candidate = self.text_buffers[1]
|
117 |
|
118 |
if len(self.text_buffers[0]) < len(candidate) >= len(self.text_buffers[2]):
|
119 |
+
action_and_sentiment = json.loads(self.get_action_and_sentiment(candidate))
|
120 |
+
if (
|
121 |
+
not isinstance(action_and_sentiment, list)
|
122 |
+
or len(action_and_sentiment) != 2
|
123 |
+
):
|
124 |
+
return None
|
125 |
+
|
126 |
+
action, sentiment = action_and_sentiment
|
127 |
|
128 |
if action not in self.valid_action:
|
129 |
action = "None"
|
|
|
148 |
|
149 |
# If we got a valid action, add it to the action queue
|
150 |
if action:
|
151 |
+
self.action_queue.put(action)
|
152 |
|
153 |
except Exception as e:
|
154 |
logger.error(f"Error processing text: {str(e)}")
|
server/__main__.py
CHANGED
@@ -32,7 +32,7 @@ STATIC_DIR = (
|
|
32 |
|
33 |
audio_queue: "Queue[io.BytesIO]" = Queue()
|
34 |
text_queue: "Queue[str]" = Queue()
|
35 |
-
action_queue: "Queue[str]" = Queue()
|
36 |
|
37 |
app = Flask(__name__, static_folder=STATIC_DIR)
|
38 |
|
|
|
32 |
|
33 |
audio_queue: "Queue[io.BytesIO]" = Queue()
|
34 |
text_queue: "Queue[str]" = Queue()
|
35 |
+
action_queue: "Queue[Dict[str, Any]]" = Queue()
|
36 |
|
37 |
app = Flask(__name__, static_folder=STATIC_DIR)
|
38 |
|
server/static/godot/index.html
CHANGED
@@ -97,7 +97,7 @@ body {
|
|
97 |
|
98 |
<script src="index.js"></script>
|
99 |
<script>
|
100 |
-
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":false,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":
|
101 |
const GODOT_THREADS_ENABLED = false;
|
102 |
const engine = new Engine(GODOT_CONFIG);
|
103 |
|
|
|
97 |
|
98 |
<script src="index.js"></script>
|
99 |
<script>
|
100 |
+
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":false,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":870496,"index.wasm":35376909},"focusCanvas":true,"gdextensionLibs":[]};
|
101 |
const GODOT_THREADS_ENABLED = false;
|
102 |
const engine = new Engine(GODOT_CONFIG);
|
103 |
|
server/static/godot/index.pck
CHANGED
Binary files a/server/static/godot/index.pck and b/server/static/godot/index.pck differ
|
|