Spaces:
Runtime error
Runtime error
Commit
Β·
6b2210c
1
Parent(s):
244aaab
Update app.py
Browse files
app.py
CHANGED
@@ -28,16 +28,6 @@ base_model = AutoModelForSeq2SeqLM.from_pretrained(
|
|
28 |
torch_dtype=torch.float32
|
29 |
)
|
30 |
|
31 |
-
|
32 |
-
# checkpoint = "LaMini-T5-738M"
|
33 |
-
# tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
34 |
-
# base_model = AutoModelForSeq2SeqLM.from_pretrained(
|
35 |
-
# checkpoint,
|
36 |
-
# device_map="auto",
|
37 |
-
# torch_dtype = torch.float32,
|
38 |
-
# from_tf=True
|
39 |
-
# )
|
40 |
-
|
41 |
persist_directory = "db"
|
42 |
|
43 |
@st.cache_resource
|
@@ -100,28 +90,28 @@ def get_file_size(file):
|
|
100 |
file.seek(0)
|
101 |
return file_size
|
102 |
|
103 |
-
|
104 |
#function to display the PDF of a given file
|
105 |
-
|
106 |
-
#
|
107 |
-
|
108 |
-
|
109 |
|
110 |
-
#
|
111 |
-
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
|
116 |
# Display conversation history using Streamlit messages
|
117 |
def display_conversation(history):
|
118 |
-
for i in range(len(
|
119 |
-
|
120 |
-
|
121 |
|
122 |
def main():
|
123 |
st.markdown("<h1 style='text-align: center; color: blue;'>Chat with your PDF π¦π </h1>", unsafe_allow_html=True)
|
124 |
-
st.markdown("<h3 style='text-align: center; color: grey;'>Built by <a href='https://github.com/
|
125 |
|
126 |
st.markdown("<h2 style='text-align: center; color:red;'>Upload your PDF π</h2>", unsafe_allow_html=True)
|
127 |
|
@@ -140,8 +130,8 @@ def main():
|
|
140 |
with col1:
|
141 |
st.markdown("<h4 style color:black;'>File details</h4>", unsafe_allow_html=True)
|
142 |
st.json(file_details)
|
143 |
-
|
144 |
-
|
145 |
|
146 |
with col2:
|
147 |
with st.spinner('Embeddings are in process...'):
|
@@ -168,12 +158,7 @@ def main():
|
|
168 |
# Display conversation history using Streamlit messages
|
169 |
if st.session_state["generated"]:
|
170 |
display_conversation(st.session_state)
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
if __name__ == "__main__":
|
179 |
main()
|
|
|
|
28 |
torch_dtype=torch.float32
|
29 |
)
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
persist_directory = "db"
|
32 |
|
33 |
@st.cache_resource
|
|
|
90 |
file.seek(0)
|
91 |
return file_size
|
92 |
|
93 |
+
@st.cache_data
|
94 |
#function to display the PDF of a given file
|
95 |
+
def displayPDF(file):
|
96 |
+
# Opening file from file path
|
97 |
+
with open(file, "rb") as f:
|
98 |
+
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
|
99 |
|
100 |
+
# Embedding PDF in HTML
|
101 |
+
pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="100%" height="600" type="application/pdf"></iframe>'
|
102 |
|
103 |
+
# Displaying File
|
104 |
+
st.markdown(pdf_display, unsafe_allow_html=True)
|
105 |
|
106 |
# Display conversation history using Streamlit messages
|
107 |
def display_conversation(history):
|
108 |
+
for i in range(len(history["generated"])):
|
109 |
+
message(history["past"][i], is_user=True, key=str(i) + "_user")
|
110 |
+
message(history["generated"][i],key=str(i))
|
111 |
|
112 |
def main():
|
113 |
st.markdown("<h1 style='text-align: center; color: blue;'>Chat with your PDF π¦π </h1>", unsafe_allow_html=True)
|
114 |
+
st.markdown("<h3 style='text-align: center; color: grey;'>Built by <a href='https://github.com/AIAnytime'>AI Anytime with β€οΈ </a></h3>", unsafe_allow_html=True)
|
115 |
|
116 |
st.markdown("<h2 style='text-align: center; color:red;'>Upload your PDF π</h2>", unsafe_allow_html=True)
|
117 |
|
|
|
130 |
with col1:
|
131 |
st.markdown("<h4 style color:black;'>File details</h4>", unsafe_allow_html=True)
|
132 |
st.json(file_details)
|
133 |
+
st.markdown("<h4 style color:black;'>File preview</h4>", unsafe_allow_html=True)
|
134 |
+
pdf_view = displayPDF(filepath)
|
135 |
|
136 |
with col2:
|
137 |
with st.spinner('Embeddings are in process...'):
|
|
|
158 |
# Display conversation history using Streamlit messages
|
159 |
if st.session_state["generated"]:
|
160 |
display_conversation(st.session_state)
|
161 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
if __name__ == "__main__":
|
163 |
main()
|
164 |
+
|