Spaces:
Runtime error
Runtime error
redis storage
Browse files
app.py
CHANGED
@@ -19,6 +19,7 @@ from langchain.schema import Document
|
|
19 |
|
20 |
from data import load_db
|
21 |
from names import DATASET_ID, MODEL_ID
|
|
|
22 |
|
23 |
|
24 |
class RetrievalType:
|
@@ -42,6 +43,9 @@ def init():
|
|
42 |
read_only=True,
|
43 |
)
|
44 |
|
|
|
|
|
|
|
45 |
prompt = PromptTemplate(
|
46 |
input_variables=["user_input"],
|
47 |
template=Path("prompts/bot.prompt").read_text(),
|
@@ -51,7 +55,7 @@ def init():
|
|
51 |
|
52 |
chain = LLMChain(llm=llm, prompt=prompt)
|
53 |
|
54 |
-
return db, chain
|
55 |
|
56 |
|
57 |
# Don't show the setting sidebar
|
@@ -61,7 +65,7 @@ if "sidebar_state" not in st.session_state:
|
|
61 |
st.set_page_config(initial_sidebar_state=st.session_state.sidebar_state)
|
62 |
|
63 |
|
64 |
-
db, chain = init()
|
65 |
|
66 |
st.title("FairytaleDJ 🎵🏰🔮")
|
67 |
st.markdown(
|
@@ -143,12 +147,15 @@ def set_song(user_input):
|
|
143 |
# take first 120 chars
|
144 |
user_input = user_input[:120]
|
145 |
docs, emotions = get_song(user_input, k=max_number_of_songs)
|
|
|
146 |
with placeholder_emotions:
|
147 |
st.markdown("Your emotions: `" + emotions + "`")
|
148 |
with placeholder:
|
149 |
iframes_html = ""
|
150 |
for doc in docs:
|
151 |
-
|
|
|
|
|
152 |
embed_url = doc.metadata["embed_url"]
|
153 |
iframes_html += (
|
154 |
f'<iframe src="{embed_url}" style="border:0;height:100px"> </iframe>'
|
@@ -158,9 +165,12 @@ def set_song(user_input):
|
|
158 |
f"<div style='display:flex;flex-direction:column'>{iframes_html}</div>",
|
159 |
unsafe_allow_html=True,
|
160 |
)
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
164 |
|
165 |
|
166 |
if run_btn:
|
|
|
19 |
|
20 |
from data import load_db
|
21 |
from names import DATASET_ID, MODEL_ID
|
22 |
+
from storage import RedisStorage, UserInput
|
23 |
|
24 |
|
25 |
class RetrievalType:
|
|
|
43 |
read_only=True,
|
44 |
)
|
45 |
|
46 |
+
storage = RedisStorage(
|
47 |
+
host=os.environ["UPSTASH_URL"], password=os.environ["UPSTASH_PASSWORD"]
|
48 |
+
)
|
49 |
prompt = PromptTemplate(
|
50 |
input_variables=["user_input"],
|
51 |
template=Path("prompts/bot.prompt").read_text(),
|
|
|
55 |
|
56 |
chain = LLMChain(llm=llm, prompt=prompt)
|
57 |
|
58 |
+
return db, storage, chain
|
59 |
|
60 |
|
61 |
# Don't show the setting sidebar
|
|
|
65 |
st.set_page_config(initial_sidebar_state=st.session_state.sidebar_state)
|
66 |
|
67 |
|
68 |
+
db, storage, chain = init()
|
69 |
|
70 |
st.title("FairytaleDJ 🎵🏰🔮")
|
71 |
st.markdown(
|
|
|
147 |
# take first 120 chars
|
148 |
user_input = user_input[:120]
|
149 |
docs, emotions = get_song(user_input, k=max_number_of_songs)
|
150 |
+
songs = []
|
151 |
with placeholder_emotions:
|
152 |
st.markdown("Your emotions: `" + emotions + "`")
|
153 |
with placeholder:
|
154 |
iframes_html = ""
|
155 |
for doc in docs:
|
156 |
+
name = doc.metadata["name"]
|
157 |
+
print(f"song = {name}")
|
158 |
+
songs.append(name)
|
159 |
embed_url = doc.metadata["embed_url"]
|
160 |
iframes_html += (
|
161 |
f'<iframe src="{embed_url}" style="border:0;height:100px"> </iframe>'
|
|
|
165 |
f"<div style='display:flex;flex-direction:column'>{iframes_html}</div>",
|
166 |
unsafe_allow_html=True,
|
167 |
)
|
168 |
+
|
169 |
+
success_storage = storage.store(
|
170 |
+
UserInput(text=user_input, emotions=emotions, songs=songs)
|
171 |
+
)
|
172 |
+
if not success_storage:
|
173 |
+
print("[ERROR] was not able to store user_input")
|
174 |
|
175 |
|
176 |
if run_btn:
|