jaothan commited on
Commit
1a544dd
·
verified ·
1 Parent(s): eb4fcaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -61
app.py CHANGED
@@ -1,61 +1,65 @@
1
- import streamlit as st
2
- import os
3
- from pathlib import Path
4
- from sentence_transformers import SentenceTransformer
5
- from streamlit_utils import local_css, remote_css, load_pdf_files
6
- from config import load_app_config, set_global_api_key
7
- from indexing_utils import ServiceContextLoader, create_multi_index
8
- from query_executers import QueryExecuter
9
-
10
-
11
- def main():
12
- """
13
- This is the main method of the streamlit application
14
- """
15
- # Set the OpenAI Api key as an environment variable
16
- set_global_api_key()
17
-
18
- dirname = Path(os.path.dirname(__file__))
19
- local_css((dirname /"style.css").as_posix())
20
- remote_css('https://fonts.googleapis.com/icon?family=Material+Icons')
21
-
22
- # Load a Configuration object for the application
23
- app_config = load_app_config()
24
-
25
- # Initialize a ServiceContext for the QueryEngine
26
- service_context = ServiceContextLoader(app_config=app_config).load()
27
-
28
- # Initialize a simple SentenceTransformer model for clustering the final responses
29
- sbert_model = SentenceTransformer(app_config.ClusteringConfig.SentenceTransformerModel)
30
-
31
- st.title("Parallel Multi-Document Question Answering")
32
-
33
- # Provide a file_uploader with drag and drop functionality
34
- multiple_files = st.file_uploader(
35
- "Drop multiple files:", accept_multiple_files=True
36
- )
37
-
38
- if multiple_files is None:
39
- st.text("No upload")
40
- else:
41
- files = [file for file in multiple_files if str(file.name).endswith(".pdf")]
42
-
43
- # Load the pdf files based on the file objects
44
- file_content_list = load_pdf_files(files=files)
45
-
46
- if file_content_list:
47
- top_k = app_config.QueryEngineConfig.similarity_top_k
48
-
49
- # Create a multi-index query engine based on the pdf file content
50
- multi_index_query_engine = create_multi_index(file_content_list=file_content_list,
51
- _service_context=service_context,
52
- top_k=top_k)
53
-
54
- # Execute the query and display the results in the streamlit app
55
- query_executer = QueryExecuter(query_engine=multi_index_query_engine,
56
- sbert_model=sbert_model,
57
- config=app_config)
58
- query_executer.run()
59
-
60
- if __name__ == "__main__":
61
- main()
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from pathlib import Path
4
+ from sentence_transformers import SentenceTransformer
5
+ from streamlit_utils import local_css, remote_css, load_pdf_files
6
+ from config import load_app_config, set_global_api_key
7
+ from indexing_utils import ServiceContextLoader, create_multi_index
8
+ from query_executers import QueryExecuter
9
+
10
+
11
+ #multi_index_demo_app.py (revoir ici )
12
+ #https://www.youtube.com/watch?v=xOOIVwH3g68
13
+
14
+
15
+ def main():
16
+ """
17
+ This is the main method of the streamlit application
18
+ """
19
+ # Set the OpenAI Api key as an environment variable
20
+ set_global_api_key()
21
+
22
+ dirname = Path(os.path.dirname(__file__))
23
+ local_css((dirname /"style.css").as_posix())
24
+ remote_css('https://fonts.googleapis.com/icon?family=Material+Icons')
25
+
26
+ # Load a Configuration object for the application
27
+ app_config = load_app_config()
28
+
29
+ # Initialize a ServiceContext for the QueryEngine
30
+ service_context = ServiceContextLoader(app_config=app_config).load()
31
+
32
+ # Initialize a simple SentenceTransformer model for clustering the final responses
33
+ sbert_model = SentenceTransformer(app_config.ClusteringConfig.SentenceTransformerModel)
34
+
35
+ st.title("Parallel Multi-Document Question Answering")
36
+
37
+ # Provide a file_uploader with drag and drop functionality
38
+ multiple_files = st.file_uploader(
39
+ "Drop multiple files:", accept_multiple_files=True
40
+ )
41
+
42
+ if multiple_files is None:
43
+ st.text("No upload")
44
+ else:
45
+ files = [file for file in multiple_files if str(file.name).endswith(".pdf")]
46
+
47
+ # Load the pdf files based on the file objects
48
+ file_content_list = load_pdf_files(files=files)
49
+
50
+ if file_content_list:
51
+ top_k = app_config.QueryEngineConfig.similarity_top_k
52
+
53
+ # Create a multi-index query engine based on the pdf file content
54
+ multi_index_query_engine = create_multi_index(file_content_list=file_content_list,
55
+ _service_context=service_context,
56
+ top_k=top_k)
57
+
58
+ # Execute the query and display the results in the streamlit app
59
+ query_executer = QueryExecuter(query_engine=multi_index_query_engine,
60
+ sbert_model=sbert_model,
61
+ config=app_config)
62
+ query_executer.run()
63
+
64
+ if __name__ == "__main__":
65
+ main()