Spaces:
Sleeping
Sleeping
sharjeel1477
commited on
Commit
•
bca1dd0
0
Parent(s):
Duplicate from sharjeel1477/admin2
Browse files- .gitattributes +35 -0
- README.md +13 -0
- app.py +177 -0
- requirements.txt +2 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Admin
|
3 |
+
emoji: 🐠
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.37.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: sharjeel1477/admin2
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pinecone
|
3 |
+
import time
|
4 |
+
import os
|
5 |
+
from pymongo.mongo_client import MongoClient
|
6 |
+
|
7 |
+
pinecone_key = os.environ['PINECONE_KEY']
|
8 |
+
|
9 |
+
|
10 |
+
def getBrains():
|
11 |
+
pinecone.init(api_key=pinecone_key,
|
12 |
+
environment="us-west4-gcp")
|
13 |
+
active_indexes = pinecone.list_indexes()
|
14 |
+
#print(active_indexes)
|
15 |
+
return gr.update(choices=active_indexes)
|
16 |
+
|
17 |
+
def isBrainFound(brainName):
|
18 |
+
pinecone.init(api_key=pinecone_key,
|
19 |
+
environment="us-west4-gcp")
|
20 |
+
active_indexes = pinecone.list_indexes()
|
21 |
+
print(active_indexes)
|
22 |
+
brainName = brainName.lower()
|
23 |
+
if brainName in active_indexes:
|
24 |
+
return True
|
25 |
+
else:
|
26 |
+
return False
|
27 |
+
|
28 |
+
def createBrain(brainName):
|
29 |
+
|
30 |
+
pinecone.init(api_key=pinecone_key,
|
31 |
+
environment="us-west4-gcp")
|
32 |
+
pinecone.create_index(
|
33 |
+
brainName,
|
34 |
+
dimension=1536,
|
35 |
+
metric="cosine",
|
36 |
+
pod_type="p1"
|
37 |
+
)
|
38 |
+
return brainName+" Brain Created!"
|
39 |
+
|
40 |
+
def delete_all_files(username):
|
41 |
+
client = MongoClient(os.environ["MONGO_KEY"])
|
42 |
+
db = client['nbrain']
|
43 |
+
collection = db['files']
|
44 |
+
query = {"brain": username}
|
45 |
+
collection.delete_many(query)
|
46 |
+
|
47 |
+
def deleteBrain(brainName):
|
48 |
+
pinecone.init(api_key=pinecone_key,
|
49 |
+
environment="us-west4-gcp")
|
50 |
+
pinecone.delete_index(brainName)
|
51 |
+
delete_all_files(brainName)
|
52 |
+
return brainName+" Brain Deleted!"
|
53 |
+
|
54 |
+
|
55 |
+
def onChange(optionVal):
|
56 |
+
if optionVal == "Create New Brain":
|
57 |
+
return [gr.update(visible=True), gr.update(visible=False)]
|
58 |
+
else:
|
59 |
+
return [gr.update(visible=False), gr.update(visible=True)]
|
60 |
+
|
61 |
+
|
62 |
+
def is_valid_string(s):
|
63 |
+
"""
|
64 |
+
Checks if a string contains only lowercase letters, numbers, and hyphens.
|
65 |
+
"""
|
66 |
+
# Define allowed characters
|
67 |
+
allowed_chars = set("abcdefghijklmnopqrstuvwxyz0123456789-")
|
68 |
+
|
69 |
+
# Check each character in the string
|
70 |
+
for char in s:
|
71 |
+
if char not in allowed_chars:
|
72 |
+
return False
|
73 |
+
|
74 |
+
# All characters are allowed
|
75 |
+
return True
|
76 |
+
|
77 |
+
get_window_url_params = """
|
78 |
+
function(url_params) {
|
79 |
+
console.log(url_params);
|
80 |
+
const params = new URLSearchParams(window.location.search);
|
81 |
+
url_params = Object.fromEntries(params);
|
82 |
+
console.log(url_params)
|
83 |
+
return url_params;
|
84 |
+
}
|
85 |
+
"""
|
86 |
+
def checkAuth(params):
|
87 |
+
print (params)
|
88 |
+
if ("password" in params):
|
89 |
+
if (params["password"] == os.environ['PASSWORD']):
|
90 |
+
return ["""# Build Brain!""", gr.update(visible=True)]
|
91 |
+
|
92 |
+
else:
|
93 |
+
return ["""# Authorization Failed!""", gr.update(visible=False)]
|
94 |
+
|
95 |
+
def handleSubmit(option, newBrainName, prevBrainName):
|
96 |
+
if option == "Create New Brain":
|
97 |
+
if (newBrainName == ""):
|
98 |
+
return "Please Enter Brain Name!"
|
99 |
+
if (isBrainFound(newBrainName) == False):
|
100 |
+
if (is_valid_string(newBrainName) == False):
|
101 |
+
return "Brain Name can only contain lowercase letters, numbers, and hyphens!"
|
102 |
+
return createBrain(newBrainName)
|
103 |
+
return newBrainName+" Brain is already created.."
|
104 |
+
if option == "Delete Brain":
|
105 |
+
print(prevBrainName)
|
106 |
+
if (prevBrainName == ""):
|
107 |
+
return "Please Select Any Brain!"
|
108 |
+
return deleteBrain(prevBrainName)
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
bg_color = "#c5dde0"
|
114 |
+
s_color = "#1d2230"
|
115 |
+
mycss = """
|
116 |
+
.gradio-container {{background-color: {bgcolor}}}
|
117 |
+
#title {{margin-top:6%;margin-bottom:16px;display:flex;justify-content:center;align-items:center}}
|
118 |
+
#title h1 {{font-weight:900;color:{scolor}}}
|
119 |
+
#secondrow {{padding:0 6%;gap:30px;display:flex;justify-content:center;align-items:center;padding-left:30%;padding-right:30%}}
|
120 |
+
#choose {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none;padding-left:0;padding-right:0}}
|
121 |
+
#choose .svelte-1gfkn6j {{background-color:{bgcolor};color:{scolor};font-size:17px}}
|
122 |
+
#namedr {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none;padding-left:0;padding-right:0}}
|
123 |
+
#namedr .svelte-1gfkn6j {{background-color:{bgcolor};color:{scolor};font-size:17px}}
|
124 |
+
#name {{background-color: {bgcolor};border-style:none;box-shadow:none;padding-left:0;padding-right:0}}
|
125 |
+
#name span {{background-color:{bgcolor};color:{scolor};font-size:17px}}
|
126 |
+
#file .svelte-1frtwj3 {{background-color:#ffffff;color:{scolor};font-size:17px}}
|
127 |
+
#file .svelte-xwlu1w {{color:{scolor};min-height:fit-content}}
|
128 |
+
#file .svelte-116rqfv {{height:15vh}}
|
129 |
+
#file .file-preview-holder {{overflow-y:scroll;max-height:17vh}}
|
130 |
+
#status {{display:flex;justify-content:center;align-items:center;margin-top:20px;font-size:20px;font-weight:700;color:{scolor}}}
|
131 |
+
#output {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none}}
|
132 |
+
#output span {{background-color:{bgcolor};color:{scolor};font-size:18px}}
|
133 |
+
#button {{background-color:{scolor};color:#ffffff;margin-top:14px}}
|
134 |
+
"""
|
135 |
+
formatted_css = mycss.format(bgcolor=bg_color, scolor=s_color)
|
136 |
+
|
137 |
+
|
138 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=formatted_css) as block_demo:
|
139 |
+
with gr.Row(elem_id="first"):
|
140 |
+
|
141 |
+
with gr.Column():
|
142 |
+
title=gr.Markdown(
|
143 |
+
"""
|
144 |
+
# Admin!
|
145 |
+
""", elem_id="title")
|
146 |
+
|
147 |
+
with gr.Row(elem_id="secondrow"):
|
148 |
+
|
149 |
+
with gr.Column(scale=1, elem_id="inputsCol") as myrow:
|
150 |
+
choose = gr.Dropdown(
|
151 |
+
label="Select Operation", value="Create New Brain", choices=["Create New Brain", "Delete Brain"], elem_id="choose", multiselect=False, interactive=True)
|
152 |
+
|
153 |
+
brain_name = gr.Textbox(
|
154 |
+
label="Brain Name", elem_id="name")
|
155 |
+
|
156 |
+
brain_name_dr = gr.Dropdown(
|
157 |
+
label="Select Brain", choices=None, elem_id="namedr", multiselect=False, interactive=True, visible=False)
|
158 |
+
|
159 |
+
choose.change(onChange, choose, [
|
160 |
+
brain_name, brain_name_dr])
|
161 |
+
|
162 |
+
|
163 |
+
submit_button = gr.Button(value="Submit", elem_id="button")
|
164 |
+
|
165 |
+
status = gr.Markdown(
|
166 |
+
"""
|
167 |
+
""", elem_id="status")
|
168 |
+
|
169 |
+
#
|
170 |
+
submit_button.click(
|
171 |
+
handleSubmit, [choose, brain_name, brain_name_dr,], status,api_name="up")
|
172 |
+
|
173 |
+
block_demo.load(checkAuth, inputs=title, outputs=[
|
174 |
+
title, myrow], _js=get_window_url_params)
|
175 |
+
block_demo.load(getBrains, inputs=None, outputs=brain_name_dr)
|
176 |
+
|
177 |
+
block_demo.launch(show_api=False)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
pinecone-client==2.2.2
|
2 |
+
pymongo==4.2
|