Skip to content

Commit

Permalink
Refactor chat interface and audiocast generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Oct 29, 2024
1 parent e0c9b19 commit bacce42
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 52 deletions.
58 changes: 7 additions & 51 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,35 @@

import streamlit as st

from src.utils.chat_thread import (
evaluate_final_response,
handle_example_prompt,
handle_user_prompt,
use_audiocast_request,
)
from src.utils.chat_utils import display_example_cards
from src.utils.render_audiocast import render_audiocast
from src.utils.render_chat import render_chat_history
from src.uis.audioui import audioui
from src.uis.chatui import chatui
from src.utils.session_state import init_session_state


async def main():
init_session_state()

# Configure page
st.set_page_config(page_title="AudioCaster", page_icon="🎧", layout="wide")
st.set_page_config(page_title="AudioCastr", page_icon="🎧", layout="wide")

# Sidebar for content type selection
st.sidebar.title("Audiocast Info")

if st.session_state.content_category:
st.sidebar.subheader(
f"Content Category: {st.session_state.content_category.capitalize()}"
)

# Main chat interface
st.title("🎧 AudioCaster")
st.title("🎧 AudioCastr")

# Declare chat interface container
uichat = st.empty()

if not st.session_state.user_specification:
with uichat.container():
st.write(
"Tell me what you'd like to listen to, and I'll create an audiocast for you!"
)

if st.session_state.messages:
render_chat_history()
elif not st.session_state.example_prompt and not st.session_state.prompt:
display_example_cards()

if st.session_state.content_category:
content_category = st.session_state.content_category

if st.session_state.example_prompt:
handle_example_prompt(content_category)

if st.session_state.prompt:
prompt = st.session_state.prompt
st.session_state.prompt = None
ai_message = handle_user_prompt(prompt, content_category)

if isinstance(ai_message, str):
await evaluate_final_response(ai_message, content_category)

# Chat input for custom prompts
if prompt := uichat.chat_input("What would you like to listen to?"):
st.session_state.messages.append({"role": "user", "content": prompt})
st.session_state.prompt = prompt
st.rerun()
await chatui(uichat)
else:
uichat.empty()
uichat = st.empty()
if not st.session_state.current_audiocast:
uichat.info("Using your audiocast specifications")

summary = st.session_state.user_specification
content_category = st.session_state.content_category
await use_audiocast_request(summary, content_category)
else:
st.info("Audiocast generation completed!")
render_audiocast()
await audioui(uichat)


if __name__ == "__main__":
Expand Down
Empty file added src/uis/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions src/uis/audioui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import streamlit as st

from src.utils.chat_thread import (
use_audiocast_request,
)
from src.utils.render_audiocast import render_audiocast


async def audioui(uichat=st.empty()):
"""
Main chat interface
"""
uichat.empty()

with st.container():
if not st.session_state.current_audiocast:
st.info("Using your audiocast specifications")

summary = st.session_state.user_specification
content_category = st.session_state.content_category
await use_audiocast_request(summary, content_category)
else:
st.info("Audiocast generation completed!")
render_audiocast()
43 changes: 43 additions & 0 deletions src/uis/chatui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import streamlit as st

from src.utils.chat_thread import (
evaluate_final_response,
handle_example_prompt,
handle_user_prompt,
)
from src.utils.chat_utils import display_example_cards
from src.utils.render_chat import render_chat_history


async def chatui(uichat=st.empty()):
"""
chat interface
"""
st.write(
"Tell me what you'd like to listen to, and I'll create an audiocast for you!"
)

if st.session_state.messages:
render_chat_history()
elif not st.session_state.example_prompt and not st.session_state.prompt:
display_example_cards()

if st.session_state.content_category:
content_category = st.session_state.content_category

if st.session_state.example_prompt:
handle_example_prompt(content_category)

if st.session_state.prompt:
prompt = st.session_state.prompt
st.session_state.prompt = None
ai_message = handle_user_prompt(prompt, content_category)

if isinstance(ai_message, str):
await evaluate_final_response(ai_message, content_category)

# Chat input for custom prompts
if prompt := uichat.chat_input("What would you like to listen to?"):
st.session_state.messages.append({"role": "user", "content": prompt})
st.session_state.prompt = prompt
st.rerun()
1 change: 0 additions & 1 deletion src/utils/chat_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def display_example_cards():
height: 125px;
white-space: normal;
word-wrap: break-word;
color: #030712
}
@media (max-width: 960px) {
div[data-testid="stColumn"] {
Expand Down

0 comments on commit bacce42

Please sign in to comment.