Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import PyPDF2
|
2 |
import streamlit as st
|
3 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
@@ -6,15 +7,6 @@ from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
6 |
tokenizer = GPT2Tokenizer.from_pretrained("openai-community/gpt2")
|
7 |
model = GPT2LMHeadModel.from_pretrained("openai-community/gpt2")
|
8 |
|
9 |
-
pdf_file = st.file_uploader("Upload an pdf file", type=["pdf"], accept_multiple_files=False)
|
10 |
-
|
11 |
-
if pdf_file is not None:
|
12 |
-
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
13 |
-
tmp_file.write(pdf_file.read())
|
14 |
-
st.success("PDF file successfully uploaded and stored temporally.")
|
15 |
-
file_path = tmp_file.name
|
16 |
-
else:
|
17 |
-
st.markdown('File not found!')
|
18 |
|
19 |
def extract_text_from_pdf(file_path):
|
20 |
text = ""
|
@@ -33,12 +25,17 @@ def generate_response(user_input):
|
|
33 |
def main():
|
34 |
st.title("PDF Chatbot")
|
35 |
|
36 |
-
|
37 |
-
uploaded_file = st.file_uploader("Upload PDF", type=["pdf"])
|
38 |
|
39 |
-
if
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
st.text_area("PDF Content", pdf_text)
|
|
|
|
|
42 |
|
43 |
user_input = st.text_input("You:", "")
|
44 |
if st.button("Send"):
|
|
|
1 |
+
import tempfile
|
2 |
import PyPDF2
|
3 |
import streamlit as st
|
4 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
|
7 |
tokenizer = GPT2Tokenizer.from_pretrained("openai-community/gpt2")
|
8 |
model = GPT2LMHeadModel.from_pretrained("openai-community/gpt2")
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def extract_text_from_pdf(file_path):
|
12 |
text = ""
|
|
|
25 |
def main():
|
26 |
st.title("PDF Chatbot")
|
27 |
|
28 |
+
pdf_file = st.file_uploader("Upload an pdf file", type=["pdf"], accept_multiple_files=False)
|
|
|
29 |
|
30 |
+
if pdf_file is not None:
|
31 |
+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
32 |
+
tmp_file.write(pdf_file.read())
|
33 |
+
st.success("PDF file successfully uploaded and stored temporally.")
|
34 |
+
file_path = tmp_file.name
|
35 |
+
pdf_text = extract_text_from_pdf(file_path)
|
36 |
st.text_area("PDF Content", pdf_text)
|
37 |
+
else:
|
38 |
+
st.markdown('File not found!')
|
39 |
|
40 |
user_input = st.text_input("You:", "")
|
41 |
if st.button("Send"):
|