Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,36 @@
|
|
1 |
import time
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
-
|
|
|
|
|
5 |
from reportlab.lib.pagesizes import letter
|
6 |
from reportlab.pdfgen import canvas
|
7 |
-
from
|
8 |
-
import search # Import the search module
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def save_as_pdf(conversation):
|
15 |
pdf_filename = "conversation.pdf"
|
@@ -68,7 +89,7 @@ def main():
|
|
68 |
if uploaded_files:
|
69 |
df = pd.DataFrame(columns=["page_num", "paragraph_num", "content", "tokens"])
|
70 |
for uploaded_file in uploaded_files:
|
71 |
-
paragraphs = search.
|
72 |
temp_df = pd.DataFrame(
|
73 |
[(p.page_num, p.paragraph_num, p.content, search.count_tokens(p.content))
|
74 |
for p in paragraphs],
|
@@ -82,7 +103,7 @@ def main():
|
|
82 |
answer = ""
|
83 |
if question != st.session_state.get("last_question", ""):
|
84 |
st.text("Searching...")
|
85 |
-
answer = search.answer_query_with_context(question, df
|
86 |
st.session_state["interactions"].append((question, answer))
|
87 |
st.write(answer)
|
88 |
|
|
|
1 |
import time
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
+
import os
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
import search # Import the search module
|
7 |
from reportlab.lib.pagesizes import letter
|
8 |
from reportlab.pdfgen import canvas
|
9 |
+
from docx import Document
|
|
|
10 |
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
st.set_page_config(
|
14 |
+
page_title="DocGPT GT",
|
15 |
+
page_icon="speech_balloon",
|
16 |
+
layout="wide",
|
17 |
+
)
|
18 |
+
|
19 |
+
hide_streamlit_style = """
|
20 |
+
<style>
|
21 |
+
#MainMenu {visibility: hidden;}
|
22 |
+
footer {visibility: hidden;}
|
23 |
+
footer:after {
|
24 |
+
content:'2023';
|
25 |
+
visibility: visible;
|
26 |
+
display: block;
|
27 |
+
position: relative;
|
28 |
+
padding: 5px;
|
29 |
+
top: 2px;
|
30 |
+
}
|
31 |
+
</style>
|
32 |
+
"""
|
33 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
34 |
|
35 |
def save_as_pdf(conversation):
|
36 |
pdf_filename = "conversation.pdf"
|
|
|
89 |
if uploaded_files:
|
90 |
df = pd.DataFrame(columns=["page_num", "paragraph_num", "content", "tokens"])
|
91 |
for uploaded_file in uploaded_files:
|
92 |
+
paragraphs = search.read_pdf_pdfminer(uploaded_file) if uploaded_file.type == "application/pdf" else search.read_docx(uploaded_file)
|
93 |
temp_df = pd.DataFrame(
|
94 |
[(p.page_num, p.paragraph_num, p.content, search.count_tokens(p.content))
|
95 |
for p in paragraphs],
|
|
|
103 |
answer = ""
|
104 |
if question != st.session_state.get("last_question", ""):
|
105 |
st.text("Searching...")
|
106 |
+
answer = search.answer_query_with_context(question, df)
|
107 |
st.session_state["interactions"].append((question, answer))
|
108 |
st.write(answer)
|
109 |
|