-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
89 lines (74 loc) · 2.6 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import glob
import streamlit as st
from elevenlabs import generate, save
from utils import answer_image_question, generate_greeting, generate_video
"""# scAIry
You think AI is scary? Wait till you see `scAIry` 👻
"""
@st.cache_resource
def get_image_list():
return sorted(glob.glob(os.path.join("data", "photos", "*")))
images = get_image_list()
image_index = st.slider(
"🎃 Choose your trick-or-treater", min_value=0, max_value=len(images) - 1
)
st.image(images[image_index])
with st.form("kiddos"):
submitted = st.form_submit_button("Choose")
if submitted:
summary = answer_image_question(
images[image_index],
"List each costume you can detect in the photo."
)
"## Summary of trick or treaters"
st.write(summary)
st.session_state["costume_summary"] = summary
if "costume_summary" in st.session_state:
GREETERS = {
"freddy_krueger": {
"name": "Freddy Krueger",
"voice_id": "0fTYMUuqMxZoSywLwS0b",
"image": "freddy.jpg"
},
"chucky": {
"name": "Chucky",
"voice_id": "zJSt7YEaVvvPws74ziWG",
"image": "chucky.jpg"
}
}
def get_greeter_name(val):
return GREETERS[val]["name"]
with st.form("greeting"):
greeter_key = st.selectbox(
"Choose a scary greeter",
options=GREETERS.keys(),
format_func=get_greeter_name,
)
greeter = GREETERS[greeter_key]
submitted = st.form_submit_button("Generate")
if submitted:
"## Scary Greeting"
with st.spinner("Generating greeting..."):
greeting = generate_greeting(
greeter["name"], st.session_state["costume_summary"]
)
st.write(greeting)
with st.spinner("Generating audio..."):
response = generate(greeting, voice=greeter["voice_id"])
file_name = f"{greeter_key}-{image_index}.wav"
file_path = os.path.join("data", "audio", file_name)
save(response, file_path)
st.audio(file_path)
st.session_state["generated_audio"] = file_path
if "generated_audio" in st.session_state:
greeter_image = os.path.join("data", "greeters", greeter["image"])
st.image(greeter_image, greeter["name"])
# This takes a bit
with st.spinner("Generating video..."):
output = generate_video(
greeter_image,
st.session_state["generated_audio"]
)
print(output)
st.video(output)