File size: 4,800 Bytes
2126dd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0fc6d
2126dd5
 
 
 
 
 
 
 
c524845
2126dd5
 
 
 
fb0ebfd
2126dd5
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
import gradio as gr
from build import updateBrain
import os
import pinecone

pinecone_key = os.environ['PINECONE_KEY']
password=os.environ['PASSWORD']


#test
get_window_url_params = """
    function(url_params) {
        var s = document.styleSheets, r,
        i, j, k;

        if(!s) return false; //no style sheets found

        // walk throuth css sheets
        
            for(i=0; i<s.length; i++) {
                try{
                    // get all rules
                    r = s[i].cssRules; 
                    if(!r) continue;

                    for(j=0; j<r.length; j++) {
                        //If there's a rule for media query
                        if(r[j] instanceof CSSMediaRule && (r[j].media.mediaText == "(min-width: 1536px)" || r[j].media.mediaText == "(min-width: 1280px)" || r[j].media.mediaText == "(min-width: 1024px)" ||
                        r[j].media.mediaText == "(min-width: 768px)" || r[j].media.mediaText == "(min-width: 640px)")) {
                            for(k=0; k<r[j].cssRules.length; k++) {
                                // remove all rules of it
                                r[j].deleteRule(r[j].cssRules[k]);
                            }
                            
                        }
                    }
                }catch(e){
                    console.log(e)
                }
            }
        

        console.log(url_params);
        const params = new URLSearchParams(window.location.search);
        url_params = Object.fromEntries(params);
        console.log(url_params)
        return url_params;
        }
    """
def isBrainFound(brainName):
    pinecone.init(api_key=pinecone_key,
                  environment="us-west4-gcp")
    active_indexes = pinecone.list_indexes()
    print(active_indexes)
    brainName = brainName.lower()
    if brainName in active_indexes:
        return True
    else:
        return False

def checkAuth(params):
    print(params)
    if ("brainName" in params):
        if(isBrainFound(params["brainName"])):
            return gr.update(visible=True),params["brainName"]
        else:
            return gr.update(visible=False),""
    else:
        return gr.update(visible=False),""


def handleSubmit(files,brainName):

    if (files == None):
        return "Please Upload Files!"
    return updateBrain(brainName, files)


bg_color = "#c5dde0"
s_color = "#003595"
light = "#666768"
mycss = """
    .gradio-container {{background-image:url("file=bg.png");background-position:center;background-size:cover;}}
    
    
    #secondrow {{margin-top:10%;padding:0 6%;gap:30px;display:flex;justify-content:center;align-items:center;padding-left:30%;padding-right:30%}}

    @media (max-width: 768px) #secondrow {{padding-left:0;padding-right:0 }}
    

    #file .svelte-1sohkj6 {{background-color:#ffffff;color:{clight};font-size:17px}}
    #file .svelte-xwlu1w {{color:{clight};min-height:fit-content}}
    #file .svelte-116rqfv {{height:15vh}}
    #file .file-preview-holder {{overflow-y:scroll;max-height:17vh}}

    #status {{display:flex;justify-content:center;align-items:center;margin-top:25px;font-size:20px;font-weight:700;color:#ffffff}}
    #status p {{color:#ffffff}}

    .built-with.svelte-1lyswbr.svelte-1lyswbr.svelte-1lyswbr {{display:none}}
    .show-api.svelte-1lyswbr.svelte-1lyswbr.svelte-1lyswbr {{display:none}}
    

    #output {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none}}
    #output span {{background-color:{bgcolor};color:{scolor};font-size:18px}}

    #button {{background-color:{scolor};color:#ffffff;margin-top:14px}}
"""
formatted_css = mycss.format(bgcolor=bg_color, scolor=s_color, clight=light)


with gr.Blocks(theme=gr.themes.Soft(), css=formatted_css) as block_demo:
    # with gr.Row(elem_id="first", visible=False):

    #     with gr.Column():
    #         title = gr.Markdown(
    #             """
    #         # Build Brain!
    #         """, elem_id="title", visible=False)
    brain = gr.State(value="")
    with gr.Row(elem_id="secondrow"):

        with gr.Column(scale=1,  elem_id="inputsCol") as myrow:

            files = gr.File(label="Upload Files", file_count="multiple",
                            file_types=[".docx", ".pdf", ".csv", ".txt", ".xml", ".json",".pptx"], elem_id="file")
            br = gr.Textbox(visible=False)
            submit_button = gr.Button(value="Submit", elem_id="button")

            status = gr.Markdown(
                """
            """, elem_id="status")

    #
    submit_button.click(
        updateBrain, [files,br], status,api_name="upload")

    block_demo.load(checkAuth, inputs=status, outputs=[myrow,brain],
                    _js=get_window_url_params)

block_demo.queue(concurrency_count=4)
block_demo.launch(show_api=False)