-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
161 lines (133 loc) · 5.95 KB
/
main.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import streamlit as st
import streamlit_authenticator as stauth
import pandas as pd
from dependencies import (
sign_up,
fetch_users,
insert_project,
get_projects,
get_files,
insert_file,
)
import traceback
from langchain_helper import get_qa_chain
st.set_page_config(page_title="Streamlit Auth", page_icon=":lock:", layout="wide")
try:
users = fetch_users()
emails = []
usernames = []
passwords = []
for user in users:
emails.append(user["email"])
usernames.append(user["username"])
passwords.append(user["password"])
credentials = {"usernames": {}}
for i in range(len(emails)):
credentials["usernames"][usernames[i]] = {
"name": emails[i],
"password": passwords[i],
}
authenticator = stauth.Authenticate(
credentials,
cookie_name="streamlit-auth",
key="abcdef",
cookie_expiry_days=4,
)
email, authentication_status, username = authenticator.login(
":green[Login]", "main"
)
info, info1 = st.columns(2)
if not authentication_status:
sign_up()
if username:
if username in usernames:
if authentication_status:
username = username[0].upper() + username[1:]
# MAIN APP
st.sidebar.subheader(f"Welcome {username.upper()}")
authenticator.logout("Log Out", "sidebar")
# Actions
projects_name = sorted(list(get_projects(email)))
projects_desc = get_projects(email)
pages = ["Home", "Create Project"] + projects_name
page = st.sidebar.selectbox("Choose a page", pages)
if page == "Home":
st.markdown(
"""
# Welcome to AnswerLLM
AnswerLLM is a sophisticated Question and Answer system that leverages pre-learned question-answer pairs to provide accurate and relevant responses to user queries. It is designed to offer quick and reliable information retrieval for various applications.
## Features
- **Pre-Learned Question-Answers**: Utilizes a database of pre-learned question-answer pairs to answer queries efficiently.
- **High Accuracy**: Designed to deliver highly accurate answers based on the trained dataset.
- **User Authentication**: Secure user authentication to manage access and user interactions.
- **Scalable Architecture**: Built to handle multiple queries simultaneously with a robust backend.
- **User-Friendly Interface**: Provides a clean and intuitive user interface for easy interaction.
"""
)
st.markdown(
"""
---
Created with ❤️ by Harsh
"""
)
elif page == "Create Project":
st.title("Create new Project")
with st.form(key="add_project", clear_on_submit=True):
project_name = st.text_input(
":blue[Project Name]", placeholder="Enter Project Name"
)
project_desc = st.text_input(
":blue[Description]",
placeholder="Enter Project Description",
)
if st.form_submit_button("Create Project"):
insert_project(email, project_name, project_desc)
st.write("Project created successfully!")
else:
st.title(page)
st.subheader(projects_desc[page]["project_desc"])
# Upload Files
with st.form(key="add_file", clear_on_submit=True):
st.subheader("Upload new File")
file_name = st.text_input(
":blue[Give your file a name]",
placeholder="Enter File Name",
)
file = st.file_uploader(
":blue[Choose a file to upload]",
type=["csv", "json", "txt"],
)
if st.form_submit_button("Add File"):
insert_file(email, page, file_name, file)
# View Files
files = get_files(email, page)
if files:
file_names = [x.replace(",", ".") for x in list(files.keys())]
for file in file_names:
with st.expander(label=file):
col1, col2 = st.columns([2, 1], gap="medium")
with col1:
df = pd.DataFrame(files[file.replace(".", ",")])
st.write(df)
with col2:
st.subheader("Questionnaires")
question = st.text_input(
"Question: ", key=page + "-" + file
)
if question:
chain = get_qa_chain(page, file)
response = chain(question)
st.subheader("Answer")
st.write(response["result"])
elif not authentication_status:
with info:
st.error("Incorrect Password or username")
else:
with info:
st.warning("Please feed in your credentials")
else:
with info:
st.warning("Username does not exist, Please Sign up")
except Exception as e:
st.error("Refresh Page")
st.error(traceback.format_exc())