Spaces:
GIZ
/
Running on CPU Upgrade

File size: 2,240 Bytes
22b8e0b
 
 
 
72e4dad
570b6e4
22b8e0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72e4dad
22b8e0b
 
 
 
 
 
 
 
 
 
72e4dad
22b8e0b
 
 
 
72e4dad
22b8e0b
b114d3b
9f55059
482fd47
72e4dad
 
 
482fd47
 
72e4dad
 
 
 
 
 
 
482fd47
72e4dad
 
 
 
 
 
482fd47
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
from streamlit_option_menu import option_menu
from utils.uploadAndExample import add_upload

class MultiApp:
    """Framework for combining multiple streamlit applications.
    Usage:
        def foo():
            st.title("Hello Foo")
        def bar():
            st.title("Hello Bar")
        app = MultiApp()
        app.add_app("Foo", foo)
        app.add_app("Bar", bar)
        app.run()
    It is also possible keep each application in a separate file.
        import foo
        import bar
        app = MultiApp()
        app.add_app("Foo", foo.app)
        app.add_app("Bar", bar.app)
        app.run()
    """
    def __init__(self):
        self.apps = []

    def add_app(self,title,icon, 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):
        
        st.sidebar.write(format_func=lambda app: app['title'])
        image = Image.open('docStore/img/sdsn.jpg')
        st.sidebar.image(image, width =200)
       
        with st.sidebar:
            selected = option_menu(None, [page["title"] for page in self.apps],
                                   icons=[page["icon"] for page in self.apps],
                                   menu_icon="cast", default_index=0)
            st.markdown("---")          
        
        
        for index, item in enumerate(self.apps):
            if item["title"] == selected:
                self.apps[index]["function"]()
                break
                
   
        choice = st.sidebar.radio(label = 'Select the Document',
                            help = 'You can upload the document \
                            or else you can try a example document', 
                            options = ('Upload Document', 'Try Example'), 
                            horizontal = True)
        add_upload(choice)