-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (64 loc) · 2.44 KB
/
Copy pathapp.py
File metadata and controls
78 lines (64 loc) · 2.44 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
72
73
74
75
76
77
78
import streamlit as st
import datetime as datetime
import requests
import json
from callollama import callOLLAMA
from prompt import prompt
st.set_page_config(
page_title= 'chatbot'
)
if "messages" not in st.session_state:#if no message is not entered
st.session_state.messages = []
st.session_state.messages.append(#after logging in it will display like this
{
"role" : "assisstant",
"content" : "Drop your message. Let me check if it is spam or ham"
}
)
if "is_typing" not in st.session_state:#if user is typing something
st.session_state.is_typing = False
st.title("OFFLINE SCAM DETECTION")
st.markdown("Welcome to AI SMS Scam Detection")
st.subheader("CHAT HERE")
for message in st.session_state.messages: #if there is any new message
if message["role"] == "user":#if that is a new user
st.info(message["content"])#it will show it as st.info #by default it will highlight the message in blue
else:
st.success(message["content"])#it will show it can be an assistant role #by default it will hightlight the message in green
if st.session_state.is_typing:
st.markdown ("Bot is typing")
st.warning ("Typing......")
st.markdown("-------")
st.subheader ("Your message :")
with st.form(key="chat_form",clear_on_submit= True):
user_input = st.text_input(
"Type Your Message",
placeholder="Ask me anything......"
)
send_button = st.form_submit_button("send message", type="primary")
col1,col2 = st.columns([1,1])
with col1:
clear_button = st.button("clear chat")#to clear the chatstreamlit run app.py
if send_button and user_input.strip():
st.session_state.messages.append(
{
"role" : "user",
"content" : user_input.strip()
}
)
#Store full messsage (with prompt) to pass to LLM
st.session_state.full_user_message = f"{prompt}<|>{user_input.strip()}"
st.session_state.is_typing = True
st.rerun()
if st.session_state.is_typing:
full_user_message = st.session_state.full_user_message
bot_response = callOLLAMA(full_user_message)#this function will connect to ollama
st.session_state.messages.append(
{
"role" : "assistant",
"content" : bot_response
}
)
st.session_state.is_typing = False
st.rerun()
st.markdown("\n\t\tMade by Tamoghno Deb")