Spaces:
Sleeping
Sleeping
Jon Taylor
commited on
Commit
·
5b6371b
1
Parent(s):
35f4179
deploy ready
Browse files- app/bot.py +3 -11
- app/pipeline.py +7 -0
- frontend/app/components/App.js +1 -1
- frontend/app/components/Call.js +5 -2
- frontend/app/components/Controls.js +22 -15
app/bot.py
CHANGED
@@ -37,10 +37,10 @@ class DailyVision(EventHandler):
|
|
37 |
self.__room_url = room_url
|
38 |
self.__room_name = room_name
|
39 |
self.__expiration = expiration
|
40 |
-
self.__params = Pipeline.InputParams()
|
41 |
self.__idle = idle
|
42 |
|
43 |
# Create the pipeline (this might take a moment)
|
|
|
44 |
self.__pipeline = Pipeline(device, torch_dtype)
|
45 |
#print(self.__pipeline.InputParams.schema())
|
46 |
|
@@ -81,10 +81,8 @@ class DailyVision(EventHandler):
|
|
81 |
|
82 |
def on_participant_joined(self, participant):
|
83 |
self.logger.info(f"Participant {participant['id']} joined, analyzing frames...")
|
84 |
-
self.__client.set_video_renderer(participant["id"], self.on_video_frame, color_format="RGB")
|
85 |
-
|
86 |
-
# Say hello
|
87 |
self.wave()
|
|
|
88 |
|
89 |
def setup_camera(self):
|
90 |
if not self.__camera:
|
@@ -135,18 +133,12 @@ class DailyVision(EventHandler):
|
|
135 |
|
136 |
def on_app_message(self, message, sender):
|
137 |
# Update pipeline settings based on message data
|
138 |
-
print(message)
|
139 |
self.__params = self.__pipeline.InputParams(**message)
|
140 |
-
print(self.__params)
|
141 |
#print(self.__pipeline.Info())
|
142 |
return
|
143 |
|
144 |
def wave(self):
|
145 |
-
self.__client.send_app_message(
|
146 |
-
{
|
147 |
-
"prompt": self.__params.prompt,
|
148 |
-
}
|
149 |
-
)
|
150 |
|
151 |
def main():
|
152 |
parser = argparse.ArgumentParser(description="Daily Bot")
|
|
|
37 |
self.__room_url = room_url
|
38 |
self.__room_name = room_name
|
39 |
self.__expiration = expiration
|
|
|
40 |
self.__idle = idle
|
41 |
|
42 |
# Create the pipeline (this might take a moment)
|
43 |
+
self.__params = Pipeline.InputParams()
|
44 |
self.__pipeline = Pipeline(device, torch_dtype)
|
45 |
#print(self.__pipeline.InputParams.schema())
|
46 |
|
|
|
81 |
|
82 |
def on_participant_joined(self, participant):
|
83 |
self.logger.info(f"Participant {participant['id']} joined, analyzing frames...")
|
|
|
|
|
|
|
84 |
self.wave()
|
85 |
+
self.__client.set_video_renderer(participant["id"], self.on_video_frame, color_format="RGB")
|
86 |
|
87 |
def setup_camera(self):
|
88 |
if not self.__camera:
|
|
|
133 |
|
134 |
def on_app_message(self, message, sender):
|
135 |
# Update pipeline settings based on message data
|
|
|
136 |
self.__params = self.__pipeline.InputParams(**message)
|
|
|
137 |
#print(self.__pipeline.Info())
|
138 |
return
|
139 |
|
140 |
def wave(self):
|
141 |
+
self.__client.send_app_message(self.__params.model_dump_json())
|
|
|
|
|
|
|
|
|
142 |
|
143 |
def main():
|
144 |
parser = argparse.ArgumentParser(description="Daily Bot")
|
app/pipeline.py
CHANGED
@@ -44,6 +44,13 @@ class Pipeline:
|
|
44 |
field="textarea",
|
45 |
id="prompt",
|
46 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
seed: int = Field(
|
48 |
4402026899276587, min=0, title="Seed", field="seed", hide=True, id="seed"
|
49 |
)
|
|
|
44 |
field="textarea",
|
45 |
id="prompt",
|
46 |
)
|
47 |
+
negative_prompt: str = Field(
|
48 |
+
default_negative_prompt,
|
49 |
+
title="Negative Prompt",
|
50 |
+
field="textarea",
|
51 |
+
id="negative_prompt",
|
52 |
+
hide=True,
|
53 |
+
)
|
54 |
seed: int = Field(
|
55 |
4402026899276587, min=0, title="Seed", field="seed", hide=True, id="seed"
|
56 |
)
|
frontend/app/components/App.js
CHANGED
@@ -25,7 +25,7 @@ export default function App({ onLeave }) {
|
|
25 |
const participantIds = useParticipantIds({ filter: "remote" });
|
26 |
const [params, setParams] = useState();
|
27 |
const sendAppMessage = useAppMessage({
|
28 |
-
onAppMessage: useCallback((ev) => setParams(ev.data), []),
|
29 |
});
|
30 |
|
31 |
return (
|
|
|
25 |
const participantIds = useParticipantIds({ filter: "remote" });
|
26 |
const [params, setParams] = useState();
|
27 |
const sendAppMessage = useAppMessage({
|
28 |
+
onAppMessage: useCallback((ev) => setParams(JSON.parse(ev.data)), []),
|
29 |
});
|
30 |
|
31 |
return (
|
frontend/app/components/Call.js
CHANGED
@@ -25,8 +25,6 @@ export default function Call() {
|
|
25 |
}
|
26 |
|
27 |
const start = useCallback(async () => {
|
28 |
-
if (!process.env.NEXT_PUBLIC_DISABLE_LOCAL_AGENT) return;
|
29 |
-
|
30 |
const resp = await fetch(`${apiUrl}/start`, {
|
31 |
method: "POST",
|
32 |
mode: "cors",
|
@@ -39,6 +37,11 @@ export default function Call() {
|
|
39 |
});
|
40 |
|
41 |
const data = await resp.json();
|
|
|
|
|
|
|
|
|
|
|
42 |
return data;
|
43 |
}, [roomUrl]);
|
44 |
|
|
|
25 |
}
|
26 |
|
27 |
const start = useCallback(async () => {
|
|
|
|
|
28 |
const resp = await fetch(`${apiUrl}/start`, {
|
29 |
method: "POST",
|
30 |
mode: "cors",
|
|
|
37 |
});
|
38 |
|
39 |
const data = await resp.json();
|
40 |
+
|
41 |
+
//@TODO error handle here
|
42 |
+
|
43 |
+
setBotState(BOT_STATE_STARTED);
|
44 |
+
|
45 |
return data;
|
46 |
}, [roomUrl]);
|
47 |
|
frontend/app/components/Controls.js
CHANGED
@@ -14,7 +14,7 @@ import {
|
|
14 |
IconPlus,
|
15 |
IconRotateClockwise,
|
16 |
} from "@tabler/icons-react";
|
17 |
-
import React, { useEffect } from "react";
|
18 |
import useDebounce from "../hooks/debounce";
|
19 |
import FieldSet from "./FieldSet";
|
20 |
import Label from "./Label";
|
@@ -23,10 +23,12 @@ import SlideInput from "./SliderInput";
|
|
23 |
import TextInput from "./TextInput";
|
24 |
|
25 |
export const Controls = React.memo(({ remoteParams, onData }) => {
|
|
|
|
|
26 |
const form = useForm({
|
27 |
initialValues: {
|
28 |
-
|
29 |
-
|
30 |
steps: 1,
|
31 |
guidance: 0.1,
|
32 |
seed: 45678,
|
@@ -36,18 +38,25 @@ export const Controls = React.memo(({ remoteParams, onData }) => {
|
|
36 |
|
37 |
const debounce = useDebounce();
|
38 |
|
39 |
-
const handleChange = (
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
42 |
|
43 |
useEffect(() => {
|
44 |
-
if (remoteParams) return;
|
45 |
-
|
|
|
|
|
|
|
|
|
46 |
|
47 |
useEffect(() => {
|
48 |
if (!form) return;
|
49 |
form.isDirty() && debounce(() => handleChange(form.values), 500);
|
50 |
-
}, [form, debounce]);
|
51 |
|
52 |
return (
|
53 |
<div className="relative flex flex-col gap-4">
|
@@ -91,10 +100,8 @@ export const Controls = React.memo(({ remoteParams, onData }) => {
|
|
91 |
autosize
|
92 |
className="rounded-md"
|
93 |
minRows={3}
|
94 |
-
defaultValue={form.getInputProps("
|
95 |
-
onChange={(e) =>
|
96 |
-
form.setFieldValue("positivePrompt", e.target.value)
|
97 |
-
}
|
98 |
classNames={{
|
99 |
input:
|
100 |
"p-3 font-mono text-emerald-800 bg-emerald-600/[0.07] border-emerald-500/30 focus:border-emerald-500 focus:ring-1 focus:ring-inset focus:ring-emerald-500",
|
@@ -112,9 +119,9 @@ export const Controls = React.memo(({ remoteParams, onData }) => {
|
|
112 |
autosize
|
113 |
className="rounded-md"
|
114 |
minRows={3}
|
115 |
-
defaultValue={form.getInputProps("
|
116 |
onChange={(e) =>
|
117 |
-
form.setFieldValue("
|
118 |
}
|
119 |
classNames={{
|
120 |
input:
|
|
|
14 |
IconPlus,
|
15 |
IconRotateClockwise,
|
16 |
} from "@tabler/icons-react";
|
17 |
+
import React, { useCallback, useEffect, useRef } from "react";
|
18 |
import useDebounce from "../hooks/debounce";
|
19 |
import FieldSet from "./FieldSet";
|
20 |
import Label from "./Label";
|
|
|
23 |
import TextInput from "./TextInput";
|
24 |
|
25 |
export const Controls = React.memo(({ remoteParams, onData }) => {
|
26 |
+
const init = useRef(false);
|
27 |
+
|
28 |
const form = useForm({
|
29 |
initialValues: {
|
30 |
+
prompt: "",
|
31 |
+
negative_prompt: "",
|
32 |
steps: 1,
|
33 |
guidance: 0.1,
|
34 |
seed: 45678,
|
|
|
38 |
|
39 |
const debounce = useDebounce();
|
40 |
|
41 |
+
const handleChange = useCallback(
|
42 |
+
(v) => {
|
43 |
+
onData(v);
|
44 |
+
},
|
45 |
+
[onData]
|
46 |
+
);
|
47 |
|
48 |
useEffect(() => {
|
49 |
+
if (!remoteParams) return;
|
50 |
+
if (!init.current) {
|
51 |
+
form.setValues(remoteParams);
|
52 |
+
init.current = true;
|
53 |
+
}
|
54 |
+
}, [form, remoteParams]);
|
55 |
|
56 |
useEffect(() => {
|
57 |
if (!form) return;
|
58 |
form.isDirty() && debounce(() => handleChange(form.values), 500);
|
59 |
+
}, [form, debounce, handleChange]);
|
60 |
|
61 |
return (
|
62 |
<div className="relative flex flex-col gap-4">
|
|
|
100 |
autosize
|
101 |
className="rounded-md"
|
102 |
minRows={3}
|
103 |
+
defaultValue={form.getInputProps("prompt").value}
|
104 |
+
onChange={(e) => form.setFieldValue("prompt", e.target.value)}
|
|
|
|
|
105 |
classNames={{
|
106 |
input:
|
107 |
"p-3 font-mono text-emerald-800 bg-emerald-600/[0.07] border-emerald-500/30 focus:border-emerald-500 focus:ring-1 focus:ring-inset focus:ring-emerald-500",
|
|
|
119 |
autosize
|
120 |
className="rounded-md"
|
121 |
minRows={3}
|
122 |
+
defaultValue={form.getInputProps("negative_prompt").value}
|
123 |
onChange={(e) =>
|
124 |
+
form.setFieldValue("negative_prompt", e.target.value)
|
125 |
}
|
126 |
classNames={{
|
127 |
input:
|