themanas021 commited on
Commit
6b2210c
Β·
1 Parent(s): 244aaab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -32
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
- # @st.cache_data
104
  #function to display the PDF of a given file
105
- # def displayPDF(file):
106
- # # Opening file from file path
107
- # with open(file, "rb") as f:
108
- # base64_pdf = base64.b64encode(f.read()).decode('utf-8')
109
 
110
- # # Embedding PDF in HTML
111
- # pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="100%" height="600" type="application/pdf"></iframe>'
112
 
113
- # # Displaying File
114
- # st.markdown(pdf_display, unsafe_allow_html=True)
115
 
116
  # Display conversation history using Streamlit messages
117
  def display_conversation(history):
118
- for i in range(len(_history["generated"])):
119
- st.message(_history["past"][i], is_user=True, key=str(i) + "_user")
120
- st.message(_history["generated"][i], key=str(i))
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/manas95826'>The Manas with ❀️ </a></h3>", unsafe_allow_html=True)
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
- # st.markdown("<h4 style color:black;'>File preview</h4>", unsafe_allow_html=True)
144
- # pdf_view = displayPDF(filepath)
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
+