-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
69 lines (56 loc) · 2.39 KB
/
Copy pathapp.py
File metadata and controls
69 lines (56 loc) · 2.39 KB
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
import streamlit as st
from ai_backend.parent_graph import multimodal_agentic_rag_graph, Chat_Input
# Configure Streamlit page
st.set_page_config(page_title="Multimodal Agentic RAG Chatbot", layout="wide")
st.title("Multimodal Agentic RAG Chatbot")
# Initialize chat history and processing state
if "history" not in st.session_state:
st.session_state.history = []
if "processing" not in st.session_state:
st.session_state.processing = False
# Display chat history (always shows up-to-date history)
for chat in st.session_state.history:
with st.chat_message("user"):
st.write(chat["user"])
with st.chat_message("assistant"):
st.write(chat["assistant"])
with st.expander("🔍 Show Context"):
st.write(chat["context"])
# Show a placeholder for the assistant's response when processing
if st.session_state.processing:
with st.chat_message("user"):
st.write(st.session_state.current_input)
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
# Process the input and get response
chat_input = Chat_Input(
prompt=st.session_state.current_input,
assistant_id="",
last_ai_message="",
tranformed_queries=[],
retrieved_docs=[],
context=[]
)
response = multimodal_agentic_rag_graph.invoke(
chat_input,
config={"configurable": {"thread_id": st.session_state.get("thread_id", 1)}}
)
assistant_msg = response.get("last_ai_message", "")
context = response.get("context", [])
# Store in history
st.session_state.history.append({
"user": st.session_state.current_input,
"assistant": assistant_msg,
"context": context
})
# Reset processing flag
st.session_state.processing = False
# Rerun to update UI without the spinner
st.rerun()
# Chat input (ChatGPT-like widget)
user_input = st.chat_input("Your message...", disabled=st.session_state.processing)
# On user submission, update state and trigger rerun
if user_input and not st.session_state.processing:
st.session_state.current_input = user_input
st.session_state.processing = True
st.rerun()