Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,55 +2,31 @@ import streamlit as st
|
|
2 |
import transformers
|
3 |
import altair as alt
|
4 |
import pandas as pd
|
5 |
-
import streamlit_authenticator as stauth
|
6 |
-
import bcrypt
|
7 |
from difflib import SequenceMatcher
|
8 |
|
9 |
# ------------------------------
|
10 |
-
#
|
11 |
# ------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
plain_password = "password123"
|
15 |
-
hashed_password = bcrypt.hashpw(plain_password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
16 |
-
|
17 |
-
# Configuration for authentication
|
18 |
-
config = {
|
19 |
-
'credentials': {
|
20 |
-
'usernames': {
|
21 |
-
'demo_user': {
|
22 |
-
'name': 'Demo User',
|
23 |
-
'password': hashed_password # use the manually hashed password
|
24 |
-
}
|
25 |
-
}
|
26 |
-
},
|
27 |
-
'cookie': {
|
28 |
-
'expiry_days': 30,
|
29 |
-
'key': 'some_signature_key',
|
30 |
-
'name': 'some_cookie_name'
|
31 |
-
},
|
32 |
-
'preauthorized': {
|
33 |
-
'emails': []
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
authenticator = stauth.Authenticate(
|
38 |
-
config['credentials'],
|
39 |
-
config['cookie']['name'],
|
40 |
-
config['cookie']['key'],
|
41 |
-
config['cookie']['expiry_days']
|
42 |
-
)
|
43 |
-
|
44 |
-
# Use 'sidebar' as the location parameter for authentication
|
45 |
-
name, authentication_status, username = authenticator.login('Login', 'sidebar')
|
46 |
-
|
47 |
-
if not authentication_status:
|
48 |
-
st.error('Authentication failed. Please refresh and try again.')
|
49 |
-
st.stop()
|
50 |
-
|
51 |
-
st.sidebar.write(f"Welcome *{name}*")
|
52 |
-
authenticator.logout('Logout', 'sidebar')
|
53 |
-
|
54 |
# ------------------------------
|
55 |
# Load Models
|
56 |
# ------------------------------
|
@@ -132,7 +108,6 @@ with tabs[1]:
|
|
132 |
answer = answer_question(summary_context, question)
|
133 |
st.subheader("Answer")
|
134 |
st.write(answer)
|
135 |
-
# For session saving, one could store Q&A pairs in st.session_state or a database.
|
136 |
else:
|
137 |
st.warning("Please provide both a summary context and a question.")
|
138 |
|
@@ -158,7 +133,6 @@ with tabs[2]:
|
|
158 |
st.subheader("Data Extraction Placeholder")
|
159 |
st.markdown("Implement NLP techniques or model prompts to extract structured data here.")
|
160 |
|
161 |
-
# File uploader example for future data extraction features
|
162 |
uploaded_file = st.file_uploader("Upload a document file for extraction", type=["pdf", "docx", "txt"])
|
163 |
if uploaded_file is not None:
|
164 |
st.info("File uploaded successfully. Data extraction logic would process this file.")
|
@@ -175,5 +149,5 @@ st.sidebar.info(
|
|
175 |
)
|
176 |
|
177 |
# ------------------------------
|
178 |
-
# End of
|
179 |
# ------------------------------
|
|
|
2 |
import transformers
|
3 |
import altair as alt
|
4 |
import pandas as pd
|
|
|
|
|
5 |
from difflib import SequenceMatcher
|
6 |
|
7 |
# ------------------------------
|
8 |
+
# Simple Authentication Setup
|
9 |
# ------------------------------
|
10 |
+
# Define a simple password for demonstration purposes.
|
11 |
+
PASSWORD = "password123"
|
12 |
+
|
13 |
+
# Initialize authentication state
|
14 |
+
if 'authenticated' not in st.session_state:
|
15 |
+
st.session_state['authenticated'] = False
|
16 |
+
|
17 |
+
# Simple password input in the sidebar for authentication
|
18 |
+
if not st.session_state['authenticated']:
|
19 |
+
st.sidebar.title("Login")
|
20 |
+
password_input = st.sidebar.text_input("Enter password:", type="password")
|
21 |
+
if st.sidebar.button("Login"):
|
22 |
+
if password_input == PASSWORD:
|
23 |
+
st.session_state['authenticated'] = True
|
24 |
+
st.sidebar.success("Authenticated!")
|
25 |
+
else:
|
26 |
+
st.sidebar.error("Incorrect password. Please try again.")
|
27 |
+
st.stop() # Stop app execution until authenticated
|
28 |
|
29 |
+
st.sidebar.write("Welcome!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# ------------------------------
|
31 |
# Load Models
|
32 |
# ------------------------------
|
|
|
108 |
answer = answer_question(summary_context, question)
|
109 |
st.subheader("Answer")
|
110 |
st.write(answer)
|
|
|
111 |
else:
|
112 |
st.warning("Please provide both a summary context and a question.")
|
113 |
|
|
|
133 |
st.subheader("Data Extraction Placeholder")
|
134 |
st.markdown("Implement NLP techniques or model prompts to extract structured data here.")
|
135 |
|
|
|
136 |
uploaded_file = st.file_uploader("Upload a document file for extraction", type=["pdf", "docx", "txt"])
|
137 |
if uploaded_file is not None:
|
138 |
st.info("File uploaded successfully. Data extraction logic would process this file.")
|
|
|
149 |
)
|
150 |
|
151 |
# ------------------------------
|
152 |
+
# End of Application
|
153 |
# ------------------------------
|