Spaces:
Sleeping
Sleeping
basic working with llama2
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
|
|
3 |
from PyPDF2 import PdfReader
|
4 |
from streamlit_extras.add_vertical_space import add_vertical_space
|
5 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
@@ -55,14 +56,21 @@ def main():
|
|
55 |
"meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3",
|
56 |
input={"prompt": prompt}
|
57 |
)
|
58 |
-
|
59 |
-
res=''
|
60 |
-
for item in output:
|
61 |
-
res+=item
|
62 |
-
response = f"AI: {res}"
|
63 |
# Display assistant response in chat message container
|
64 |
with st.chat_message("assistant"):
|
65 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
# Add assistant response to chat history
|
67 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
68 |
# https://replicate.com/meta/llama-2-70b-chat/versions/02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3/api#output-schema
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
+
import time
|
4 |
from PyPDF2 import PdfReader
|
5 |
from streamlit_extras.add_vertical_space import add_vertical_space
|
6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
56 |
"meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3",
|
57 |
input={"prompt": prompt}
|
58 |
)
|
59 |
+
|
|
|
|
|
|
|
|
|
60 |
# Display assistant response in chat message container
|
61 |
with st.chat_message("assistant"):
|
62 |
+
message_placeholder = st.empty()
|
63 |
+
|
64 |
+
# The predict method returns an iterator, and you can iterate over that output.
|
65 |
+
response_till_now=''
|
66 |
+
for item in output:
|
67 |
+
response_till_now+=item
|
68 |
+
time.sleep(0.05)
|
69 |
+
message_placeholder.markdown(response_till_now + "▌")
|
70 |
+
message_placeholder.markdown(response_till_now)
|
71 |
+
response = f"AI: {response_till_now}"
|
72 |
+
|
73 |
+
|
74 |
# Add assistant response to chat history
|
75 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
76 |
# https://replicate.com/meta/llama-2-70b-chat/versions/02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3/api#output-schema
|