-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (51 loc) · 1.58 KB
/
app.py
File metadata and controls
66 lines (51 loc) · 1.58 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
import streamlit as st
import ollama
import json
st.set_page_config(page_title="Nectar AI Chatbot", layout="wide")
st.title("🤖 Nectar`s AI Chatbot")
# Sidebar controls
st.sidebar.header("⚙️ Settings")
model_choice = st.sidebar.selectbox(
"Choose Model",
["phi"],
index=0
)
if st.sidebar.button("🗑 Clear Chat"):
st.session_state.messages = []
st.rerun()
# Export chat button
if st.sidebar.button("💾 Export Chat"):
if "messages" in st.session_state and st.session_state.messages:
chat_json = json.dumps(st.session_state.messages, indent=2)
st.sidebar.download_button(
label="Download Chat",
data=chat_json,
file_name="chat_history.json",
mime="application/json"
)
# Initialize memory
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat history
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.write(msg["content"])
# Chat input
user_input = st.chat_input("Type your message...")
if user_input:
st.session_state.messages.append(
{"role": "user", "content": user_input}
)
with st.chat_message("user"):
st.write(user_input)
with st.spinner("Thinking..."):
response = ollama.chat(
model=model_choice,
messages=st.session_state.messages
)
ai_reply = response["message"]["content"]
st.session_state.messages.append(
{"role": "assistant", "content": ai_reply}
)
with st.chat_message("assistant"):
st.write(ai_reply)