-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (54 loc) · 2.15 KB
/
app.py
File metadata and controls
71 lines (54 loc) · 2.15 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
70
71
from pipeline.pipeline import Pipeline
import streamlit as st
# Set page configuration as the very first Streamlit command.
st.set_page_config(
page_title="AI Assistant 🤖",
page_icon="🤖",
layout="wide"
)
def load_pipeline():
return Pipeline()
pipeline = load_pipeline()
def get_response(model_number, query):
"""Generate a response based on the selected model and user query."""
model_names = ["Gemini", "DeepSeek"]
if "chat_history" in st.session_state:
chat_history = st.session_state.chat_history
else:
chat_history = []
response = pipeline.predict(query, model_number, chat_history)
return f"**{model_names[model_number]} says:** {response}"
def main():
# Initialize chat history in session state if not already present
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# --- Sidebar ---
st.sidebar.title("Options")
models = ["Gemini", "DeepSeek"]
selected_model = st.sidebar.selectbox("Select a Model", models)
model_number = models.index(selected_model)
if st.sidebar.button("Clear Chat History"):
st.session_state.chat_history = []
st.experimental_rerun()
st.title("AI Assistant")
# Display existing chat history
for message in st.session_state.chat_history:
with st.chat_message(message["role"]):
st.markdown(message["content"], unsafe_allow_html=True)
# Initial greeting if no conversation exists
if not st.session_state.chat_history:
with st.chat_message("assistant"):
st.markdown(
"Hello! Select a model from the sidebar and ask me anything about AI.")
# Accept user input
user_input = st.chat_input("Type your message here")
if user_input:
st.session_state.chat_history.append(
{"role": "user", "content": user_input})
response = get_response(model_number, user_input)
st.session_state.chat_history.append(
{"role": "assistant", "content": response})
with st.chat_message("assistant"):
st.markdown(response, unsafe_allow_html=True)
if __name__ == "__main__":
main()