Spaces:
Sleeping
Sleeping
elia-waefler
commited on
Commit
•
3663ccd
1
Parent(s):
c450ce3
added openai api key pw field
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import time
|
2 |
import streamlit as st
|
3 |
-
from dotenv import load_dotenv
|
4 |
from PyPDF2 import PdfReader
|
5 |
from langchain.text_splitter import CharacterTextSplitter
|
6 |
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
|
@@ -11,7 +10,7 @@ from langchain.chains import ConversationalRetrievalChain
|
|
11 |
import os
|
12 |
import pickle
|
13 |
from datetime import datetime
|
14 |
-
from backend.generate_metadata import
|
15 |
|
16 |
|
17 |
css = '''
|
@@ -43,7 +42,8 @@ css = '''
|
|
43 |
bot_template = '''
|
44 |
<div class="chat-message bot">
|
45 |
<div class="avatar">
|
46 |
-
<img src="https://i.ibb.co/cN0nmSj/Screenshot-2023-05-28-at-02-37-21.png"
|
|
|
47 |
</div>
|
48 |
<div class="message">{{MSG}}</div>
|
49 |
</div>
|
@@ -67,7 +67,6 @@ def get_pdf_text(pdf_docs):
|
|
67 |
return text
|
68 |
|
69 |
|
70 |
-
|
71 |
def get_text_chunks(text):
|
72 |
text_splitter = CharacterTextSplitter(
|
73 |
separator="\n",
|
@@ -132,12 +131,20 @@ def safe_vec_store():
|
|
132 |
|
133 |
|
134 |
def main():
|
135 |
-
load_dotenv()
|
136 |
st.set_page_config(page_title="Doc Verify RAG", page_icon=":hospital:")
|
137 |
st.write(css, unsafe_allow_html=True)
|
138 |
-
if
|
|
|
|
|
|
|
|
|
139 |
st.session_state.classify = False
|
|
|
|
|
140 |
st.subheader("Your documents")
|
|
|
|
|
|
|
141 |
if st.session_state.classify:
|
142 |
pdf_doc = st.file_uploader("Upload your PDFs here and click on 'Process'", accept_multiple_files=False)
|
143 |
else:
|
@@ -149,7 +156,7 @@ def main():
|
|
149 |
# THE CLASSIFICATION APP
|
150 |
st.write("Classifying")
|
151 |
plain_text_doc = ingest(pdf_doc.name)
|
152 |
-
classification_result =
|
153 |
st.write(classification_result)
|
154 |
else:
|
155 |
# NORMAL RAG
|
|
|
1 |
import time
|
2 |
import streamlit as st
|
|
|
3 |
from PyPDF2 import PdfReader
|
4 |
from langchain.text_splitter import CharacterTextSplitter
|
5 |
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
|
|
|
10 |
import os
|
11 |
import pickle
|
12 |
from datetime import datetime
|
13 |
+
from backend.generate_metadata import generate_metadata, ingest
|
14 |
|
15 |
|
16 |
css = '''
|
|
|
42 |
bot_template = '''
|
43 |
<div class="chat-message bot">
|
44 |
<div class="avatar">
|
45 |
+
<img src="https://i.ibb.co/cN0nmSj/Screenshot-2023-05-28-at-02-37-21.png"
|
46 |
+
style="max-height: 78px; max-width: 78px; border-radius: 50%; object-fit: cover;">
|
47 |
</div>
|
48 |
<div class="message">{{MSG}}</div>
|
49 |
</div>
|
|
|
67 |
return text
|
68 |
|
69 |
|
|
|
70 |
def get_text_chunks(text):
|
71 |
text_splitter = CharacterTextSplitter(
|
72 |
separator="\n",
|
|
|
131 |
|
132 |
|
133 |
def main():
|
|
|
134 |
st.set_page_config(page_title="Doc Verify RAG", page_icon=":hospital:")
|
135 |
st.write(css, unsafe_allow_html=True)
|
136 |
+
if "openai_api_key" not in st.session_state:
|
137 |
+
st.session_state.openai_api_key = False
|
138 |
+
if "openai_org" not in st.session_state:
|
139 |
+
st.session_state.openai_org = False
|
140 |
+
if "classify" not in st.session_state:
|
141 |
st.session_state.classify = False
|
142 |
+
def set_pw():
|
143 |
+
st.session_state.openai_api_key = True
|
144 |
st.subheader("Your documents")
|
145 |
+
# OPENAI_ORG_ID = st.text_input("OPENAI ORG ID:")
|
146 |
+
OPENAI_API_KEY = st.text_input("OPENAI API KEY:", type="password",
|
147 |
+
disabled=st.session_state.openai_api_key, on_change=set_pw)
|
148 |
if st.session_state.classify:
|
149 |
pdf_doc = st.file_uploader("Upload your PDFs here and click on 'Process'", accept_multiple_files=False)
|
150 |
else:
|
|
|
156 |
# THE CLASSIFICATION APP
|
157 |
st.write("Classifying")
|
158 |
plain_text_doc = ingest(pdf_doc.name)
|
159 |
+
classification_result = generate_metadata(plain_text_doc)
|
160 |
st.write(classification_result)
|
161 |
else:
|
162 |
# NORMAL RAG
|