-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp (2).py
55 lines (42 loc) · 1.65 KB
/
app (2).py
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
import streamlit as st
import llama2
tokenizer, LLM, embedding_model = llama2.load_model(
"krthk/llama-2-7b-chat-finetuned"
) # Huggingface model id
def main():
st.title("Talking docs")
# File upload
files = st.file_uploader(label="Upload your documents", accept_multiple_files=True)
st.sidebar.markdown("# Uploaded Files 📂\n")
# Display uploaded files in the sidebar
for file in files or []:
st.sidebar.write(f"### 📄 {file.name}")
if files:
res = llama2.get_summary(files, LLM, tokenizer, embedding_model)
with st.chat_message("assistant"):
for i in res:
st.write(f"Summary: {i}")
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("Enter your prompt or summarize about..."):
# Display user message in chat message container
with st.chat_message("human"):
st.markdown(prompt)
# Add user message to chat history
st.session_state.messages.append(
{"role": "user", "content": f"User: {prompt}"}
)
# Display assistant response in chat message container
with st.chat_message("ai"):
st.markdown(f"Kolol: {prompt}")
# Add assistant response to chat history
st.session_state.messages.append(
{"role": "assistant", "content": f"Kolol: {prompt}"}
)
if __name__ == "__main__":
main()