Spaces:
Runtime error
Runtime error
File size: 2,331 Bytes
ed1a990 c018f56 ed1a990 2bc3b44 2d5d387 2bc3b44 ed1a990 0a25c1f ed1a990 2de3f44 ed1a990 d5e831b 06b12cc d5e831b ed1a990 2eae674 ed1a990 88838a9 ed1a990 ade184d 07c7a77 0a25c1f eea1b81 55565cd 06b12cc |
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 |
"""Frameworks for running multiple Streamlit applications as a single app.
"""
import streamlit as st
from PIL import Image
import tempfile
import logging
from sklearn.feature_extraction import _stop_words
from haystack.document_stores import InMemoryDocumentStore
from haystack.pipelines import ExtractiveQAPipeline
from haystack.nodes import FARMReader, TfidfRetriever
import scripts.process as pre
import scripts.clean as clean
logger = logging.getLogger(__name__)
# Initialization
if 'file' not in st.session_state:
st.session_state['pipeline'] = None
class MultiApp:
"""
Framework for combining multiple streamlit applications.
"""
def __init__(self):
self.apps = []
def add_app(self, title, func):
"""Adds a new application.
Parameters
----------
func:
the python function to render this app.
title:
title of the app. Appears in the dropdown in the sidebar.
"""
self.apps.append({
"title": title,
# "icon": icon,
"function": func
})
def run(self):
if 'file' not in st.session_state:
st.session_state['pipeline'] = None
st.sidebar.write(format_func=lambda app: app['title'])
image = Image.open('appStore/img/sdsn.png')
st.sidebar.image(image)
app = st.sidebar.radio(
'Pages',
self.apps,
format_func=lambda app: app['title'])
app['function']()
st.sidebar.markdown('')
st.sidebar.markdown("## 📌 Upload document ")
file = st.sidebar.file_uploader('', type=['pdf', 'docx', 'txt']) #Upload PDF File
if file is not None:
with tempfile.NamedTemporaryFile(mode="wb") as temp:
bytes_data = file.getvalue()
temp.write(bytes_data)
file_name = file.name
file_path = temp.name
st.write("Filename: ", file.name)
# load document
documents = pre.load_document(temp.name,file_name)
documents_processed = pre.preprocessing(documents)
pipeline = start_haystack(documents_processed)
st.session_state['pipeline'] = pipeline |