-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
112 lines (89 loc) · 3.72 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
main program to launch the streamlit app for local LLM inference over a document
"""
import streamlit as st
import llm
import db
if "model" not in st.session_state:
st.session_state["model"] = ''
if "file" not in st.session_state:
st.session_state["file"] = ''
st.set_page_config(layout="wide", page_title='FileGPT: Local cognitive search over a document',
page_icon='./media/favicon.png')
with open('css.py', encoding='utf_8') as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.markdown('<h2>🗂️ FileGPT</h2>',
unsafe_allow_html=True)
st.markdown("""---""")
model_list = [''] + llm.get_models()
with st.sidebar:
st.markdown(
"## How to use :\n"
"1. Select a model 💻\n"
"2. Upload a pdf file (no ocr support)📄\n"
"3. Ask a question about the document ❓\n"
)
st.markdown("""---""")
selection = st.selectbox(
'1-Select Model', model_list)
if selection != '':
with st.spinner("Loading model.."):
model = llm.LlmModel(selection)
model.load_model()
pdf_file = st.file_uploader("2 - File Upload", type=[
'pdf'], accept_multiple_files=False)
if pdf_file is not None:
with st.spinner("Loading file.."):
data = db.Data(pdf_file)
data.load_docs()
data.gen_vectorstore(chunk_size=500, chunk_overlap=100)
st.markdown("---")
st.markdown("# About")
st.markdown(
"🗂️ FileGPT allows you to ask questions about your "
"documents and get answers without your data leaving your network. "
)
st.markdown(
"It lets you evaluate various LLM models and choose the one that works best for you.\
This is a work in progress. For feedback and suggestions: \
[GitHub](https://github.com/ankurkaul17/file_gpt)."
)
st.markdown(
"Made by [Ankur Kaul](https://www.linkedin.com/in/ankurkaul17)"
)
st.markdown("---")
st.markdown(
"""
# FAQ
## How to add new models?
You can create a new folder inside the '/models' directory and place downloaded
models there. Make sure to keep the folder name same as the model bin file name.
## Is my data safe?
Yes, your data is safe. FileGPT stores your documents as embedding in a local
directory called 'db'. The data does not leave your network. Questions and responses
are not stored.
## Why does it take so long to run?
Since the whole operation runs locally, the speed of inferencing depends on the
local hardware. CPU's are usually slow at running LLM models than GPU's.
## Are the answers 100% accurate?
No, the answers are not 100% accurate. The quality of the answer depends on the LLM
that you are using. These LLM's sometimes make mistakes and are prone to hallucinations.
But for most use cases, it is quite accurate and can answer most questions. Always
check with the sources to make sure that the answers are correct.
"""
)
l_col, r_col = st.columns((1.5, 1))
with l_col:
question = st.text_area("3 - Ask a Question", height=30)
response = st.empty()
if st.button('Get Response'):
ans = model.get_answer(
ques=question, retriever=data.retriever)
response.text_area('Response', value=ans, height=250)
with r_col:
if pdf_file is None:
st.text_area(
'Document Preview: Raw Text', height=650, placeholder="Upload file first !!!", disabled=True)
else:
preview = st.text_area(
'Document Preview: Raw Text', height=650, value=data.documents)