Spaces:
Running
Running
Update ui.py
Browse files
ui.py
CHANGED
@@ -1,280 +1,177 @@
|
|
1 |
-
import streamlit as st
|
2 |
import requests
|
3 |
import os
|
4 |
from gliner import GLiNER
|
5 |
-
#from auth import authenticator
|
6 |
from streamlit_autorefresh import st_autorefresh
|
7 |
|
|
|
8 |
|
9 |
-
|
10 |
-
tok=os.getenv("TOK")
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
"----------------------------------------------"
|
15 |
-
|
16 |
-
|
17 |
-
st_autorefresh(interval=5000,key="volter")
|
18 |
-
|
19 |
-
|
20 |
-
"----------------------------------------------"
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
|
26 |
def Target_Identification(userinput):
|
27 |
-
|
28 |
-
|
29 |
model = GLiNER.from_pretrained("Ihor/gliner-biomed-bi-small-v1.0")
|
30 |
labels = ["Protein"]
|
31 |
-
|
32 |
entities = model.predict_entities(userinput, labels, threshold=0.5)
|
33 |
|
34 |
-
|
35 |
-
result={}
|
36 |
for entity in entities:
|
37 |
-
if entity["label"] =="Protein":
|
38 |
return entity["text"]
|
39 |
|
40 |
|
41 |
-
|
42 |
def APP():
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
"TABS",
|
53 |
-
options=tab_map.keys(),
|
54 |
-
format_func=lambda option:tab_map[option],
|
55 |
-
selection_mode="single"
|
56 |
-
|
57 |
-
)
|
58 |
-
|
59 |
-
def SHOWTABS():
|
60 |
-
|
61 |
-
|
62 |
-
if tab_selection == 0 :
|
63 |
-
|
64 |
-
|
65 |
option_map = {
|
66 |
-
|
67 |
0: "@OriginAI Nanobody Engineering:",
|
68 |
-
|
69 |
-
#2: "Information"
|
70 |
-
}
|
71 |
-
|
72 |
selection = st.pills(
|
73 |
"BIOLOGICS",
|
74 |
options=option_map.keys(),
|
75 |
format_func=lambda option: option_map[option],
|
76 |
selection_mode="single",
|
77 |
-
|
78 |
-
|
79 |
if selection == 0:
|
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 |
-
if len(projects) > 0 :
|
120 |
-
|
121 |
-
option = st.selectbox(
|
122 |
-
"selectproject",
|
123 |
-
projects
|
124 |
-
)
|
125 |
-
projectname = option
|
126 |
-
|
127 |
-
#if projectname == "":
|
128 |
-
# with st.expander("Set up the project before proceeding."):
|
129 |
-
# projectname = st.text_input("Provide project name > ")
|
130 |
-
|
131 |
-
elif len(projects) == 0:
|
132 |
-
|
133 |
-
p_name=st.text_input("enter project name : ")
|
134 |
-
projectname=p_name
|
135 |
-
|
136 |
-
|
137 |
-
#bio_input = st.text_area(
|
138 |
-
# "Protein Engineering Query",
|
139 |
-
# placeholder="Type your query here."
|
140 |
-
#)
|
141 |
-
#execute_button=st.form_submit_button("execute")
|
142 |
-
bio_input = st.chat_input(" Ready for Action ! ")
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
"""----------------experimental--------------------"""
|
148 |
-
@st.cache_data(ttl=10)
|
149 |
-
def fetch_ops():
|
150 |
-
response=requests.get(f"https://thexforce-combat-backend.hf.space/user/operations/{st.user.email}",
|
151 |
-
headers={
|
152 |
-
|
153 |
-
"Content-Type":"application/json",
|
154 |
-
"Authorization":f"Bearer {tok}"
|
155 |
-
})
|
156 |
-
useroperations_json=response.json()
|
157 |
-
return useroperations_json
|
158 |
-
|
159 |
-
|
160 |
-
"""---------------experimental-----------------------"""
|
161 |
-
|
162 |
-
with st.container():
|
163 |
-
if len(st.session_state.messages) > 0:
|
164 |
-
for msg in st.session_state.messages:
|
165 |
-
with st.chat_message(msg["role"]):
|
166 |
-
st.markdown(msg["content"])
|
167 |
-
|
168 |
-
if bio_input:
|
169 |
-
|
170 |
-
st.session_state.messages.append({"role":"user","content":bio_input})
|
171 |
-
with st.chat_message("user"):
|
172 |
-
st.markdown(bio_input)
|
173 |
-
|
174 |
-
if projectname == None or projectname == "":
|
175 |
-
st.markdown(":orange-badge[⚠️Set Projectname]")
|
176 |
-
else:
|
177 |
-
|
178 |
-
identified_target=Target_Identification(bio_input)
|
179 |
-
st.warning(f"TARGET IDENTIFIED IS :{identified_target}")
|
180 |
-
|
181 |
-
payload={
|
182 |
-
"uid":st.user.email ,
|
183 |
-
"pid":projectname,
|
184 |
-
"target":identified_target or None,
|
185 |
-
"high_level_bio_query":bio_input
|
186 |
-
}
|
187 |
-
|
188 |
-
|
189 |
-
response=requests.post("https://thexforce-combat-backend.hf.space/application_layer_agent",json=payload,headers={
|
190 |
-
|
191 |
-
"Content-Type":"application/json",
|
192 |
-
"Authorization":f"Bearer {tok}"
|
193 |
-
})
|
194 |
-
|
195 |
-
plan_response=response.json()
|
196 |
-
|
197 |
-
|
198 |
-
#st.markdown(f"## {plan_response}")
|
199 |
-
with st.chat_message("assistant"):
|
200 |
-
st.markdown(plan_response)
|
201 |
-
|
202 |
-
|
203 |
-
"---------------------experimental--------------------------------"
|
204 |
-
fetch_ops_response=fetch_ops()
|
205 |
-
if fetch_ops_response.get("exp") != None:
|
206 |
-
for op in fetch_ops_response.get("exp"):
|
207 |
-
|
208 |
-
with st.chat_message("assistant"):
|
209 |
-
st.markdown(op.get("operation"))
|
210 |
-
st.markdown(op.get("output"))
|
211 |
-
"------------------------------------------------------------------"
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
st.session_state.messages.append({"role":"assistant","content":plan_response})
|
216 |
-
|
217 |
-
|
218 |
-
#if selection == 1:
|
219 |
-
#st.markdown("<p style='color:white;background-color:orange;font-weight:bold'>Vaccine [Supported] </p>",unsafe_allow_html=True)
|
220 |
-
#with st.expander("info"):
|
221 |
-
#st.info("",icon=":material/info:")
|
222 |
-
#st.code("coming soon")
|
223 |
-
|
224 |
-
#if selection ==2:
|
225 |
-
#st.markdown("<p style='color:white;background-color:orange;font-weight:bold'>Operation Details </p>",unsafe_allow_html=True)
|
226 |
-
|
227 |
-
|
228 |
-
#if tab_selection == 1:
|
229 |
-
#st.markdown("### ORIGINAI Bio Lab Operations")
|
230 |
-
|
231 |
-
#@st.cache_data(ttl=10)
|
232 |
-
#def fetch_ops():
|
233 |
-
#response=requests.get(f"https://thexforce-combat-backend.hf.space/user/operations/{st.user.email}",headers={
|
234 |
-
|
235 |
-
# "Content-Type":"application/json",
|
236 |
-
# "Authorization":f"Bearer {tok}"
|
237 |
-
#})
|
238 |
-
#useroperations_json=response.json()
|
239 |
-
#return useroperations_json
|
240 |
-
|
241 |
-
#userops=fetch_ops()
|
242 |
-
|
243 |
-
## st.json(userops)
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
'''
|
248 |
-
response=requests.get(
|
249 |
-
|
250 |
-
f"https://thexforce-combat-backend.hf.space/{st.session_state.get('username')}/{projectname}/individual/experiment",
|
251 |
headers={
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
st.
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
import requests
|
3 |
import os
|
4 |
from gliner import GLiNER
|
|
|
5 |
from streamlit_autorefresh import st_autorefresh
|
6 |
|
7 |
+
tok = os.getenv("TOK")
|
8 |
|
9 |
+
st_autorefresh(interval=5000, key="volter")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def Target_Identification(userinput):
|
|
|
|
|
13 |
model = GLiNER.from_pretrained("Ihor/gliner-biomed-bi-small-v1.0")
|
14 |
labels = ["Protein"]
|
|
|
15 |
entities = model.predict_entities(userinput, labels, threshold=0.5)
|
16 |
|
|
|
|
|
17 |
for entity in entities:
|
18 |
+
if entity["label"] == "Protein":
|
19 |
return entity["text"]
|
20 |
|
21 |
|
|
|
22 |
def APP():
|
23 |
+
tab_map = {
|
24 |
+
0: "BIO ENGINEERING LAB @newMATTER",
|
25 |
+
}
|
26 |
+
|
27 |
+
tab_selection = st.pills(
|
28 |
+
"TABS",
|
29 |
+
options=tab_map.keys(),
|
30 |
+
format_func=lambda option: tab_map[option],
|
31 |
+
selection_mode="single",
|
32 |
+
)
|
33 |
+
|
34 |
+
def SHOWTABS():
|
35 |
+
if tab_selection == 0:
|
36 |
+
# Two-column split
|
37 |
+
left_col, right_col = st.columns([0.4, 0.6])
|
38 |
+
|
39 |
+
# CSS to make right column sticky
|
40 |
+
st.markdown("""
|
41 |
+
<style>
|
42 |
+
[data-testid="column"]:nth-of-type(2) {
|
43 |
+
position: sticky;
|
44 |
+
top: 0;
|
45 |
+
align-self: flex-start;
|
46 |
+
height: 100vh;
|
47 |
+
overflow-y: auto;
|
48 |
+
background-color: #0E1117;
|
49 |
+
padding: 10px;
|
50 |
+
border-left: 1px solid rgba(255,255,255,0.1);
|
51 |
}
|
52 |
+
</style>
|
53 |
+
""", unsafe_allow_html=True)
|
54 |
|
55 |
+
with left_col:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
option_map = {
|
|
|
57 |
0: "@OriginAI Nanobody Engineering:",
|
58 |
+
}
|
|
|
|
|
|
|
59 |
selection = st.pills(
|
60 |
"BIOLOGICS",
|
61 |
options=option_map.keys(),
|
62 |
format_func=lambda option: option_map[option],
|
63 |
selection_mode="single",
|
64 |
+
)
|
65 |
+
|
66 |
if selection == 0:
|
67 |
+
st.markdown(
|
68 |
+
"<p style='color:white;background-color:orange;font-weight:bold'> Nanobody [CANCER targeted]</p>",
|
69 |
+
unsafe_allow_html=True,
|
70 |
+
)
|
71 |
+
|
72 |
+
projects = []
|
73 |
+
projectname = None
|
74 |
+
|
75 |
+
def scan_for_project_availability(user_id):
|
76 |
+
request_url = f"https://thexforce-combat-backend.hf.space/{user_id}/projects"
|
77 |
+
response = requests.get(
|
78 |
+
request_url,
|
79 |
+
headers={
|
80 |
+
"Content-Type": "application/json",
|
81 |
+
"Authorization": f"Bearer {tok}",
|
82 |
+
},
|
83 |
+
)
|
84 |
+
response_json = response.json()
|
85 |
+
pros = response_json.get("projects")
|
86 |
+
for pro in pros:
|
87 |
+
projects.append(pro.get("project"))
|
88 |
+
|
89 |
+
scan_for_project_availability(st.user.email)
|
90 |
+
|
91 |
+
if len(projects) > 0:
|
92 |
+
projectname = st.selectbox("Select Project", projects)
|
93 |
+
else:
|
94 |
+
projectname = st.text_input("Enter project name:")
|
95 |
+
|
96 |
+
st.session_state.projectname = projectname
|
97 |
+
|
98 |
+
with right_col:
|
99 |
+
bio_input = st.chat_input(" Ready for Action ! ")
|
100 |
+
|
101 |
+
@st.cache_data(ttl=10)
|
102 |
+
def fetch_ops():
|
103 |
+
response = requests.get(
|
104 |
+
f"https://thexforce-combat-backend.hf.space/user/operations/{st.user.email}",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
headers={
|
106 |
+
"Content-Type": "application/json",
|
107 |
+
"Authorization": f"Bearer {tok}",
|
108 |
+
},
|
109 |
+
)
|
110 |
+
return response.json()
|
111 |
+
|
112 |
+
if "messages" not in st.session_state:
|
113 |
+
st.session_state.messages = []
|
114 |
+
|
115 |
+
if len(st.session_state.messages) > 0:
|
116 |
+
for msg in st.session_state.messages:
|
117 |
+
with st.chat_message(msg["role"]):
|
118 |
+
st.markdown(msg["content"])
|
119 |
+
|
120 |
+
if bio_input:
|
121 |
+
st.session_state.messages.append({"role": "user", "content": bio_input})
|
122 |
+
with st.chat_message("user"):
|
123 |
+
st.markdown(bio_input)
|
124 |
+
|
125 |
+
if st.session_state.projectname in [None, ""]:
|
126 |
+
st.markdown(":orange-badge[⚠️ Set Projectname]")
|
127 |
+
else:
|
128 |
+
identified_target = Target_Identification(bio_input)
|
129 |
+
st.warning(f"TARGET IDENTIFIED IS : {identified_target}")
|
130 |
+
|
131 |
+
payload = {
|
132 |
+
"uid": st.user.email,
|
133 |
+
"pid": st.session_state.projectname,
|
134 |
+
"target": identified_target or None,
|
135 |
+
"high_level_bio_query": bio_input,
|
136 |
+
}
|
137 |
+
|
138 |
+
response = requests.post(
|
139 |
+
"https://thexforce-combat-backend.hf.space/application_layer_agent",
|
140 |
+
json=payload,
|
141 |
+
headers={
|
142 |
+
"Content-Type": "application/json",
|
143 |
+
"Authorization":f"Bearer {tok}",
|
144 |
+
},
|
145 |
+
)
|
146 |
+
|
147 |
+
plan_response = response.json()
|
148 |
+
|
149 |
+
with st.chat_message("assistant"):
|
150 |
+
st.markdown(plan_response)
|
151 |
+
|
152 |
+
fetch_ops_response = fetch_ops()
|
153 |
+
if fetch_ops_response.get("exp") is not None:
|
154 |
+
for op in fetch_ops_response.get("exp"):
|
155 |
+
with st.chat_message("assistant"):
|
156 |
+
st.markdown(op.get("operation"))
|
157 |
+
st.markdown(op.get("output"))
|
158 |
+
|
159 |
+
st.session_state.messages.append(
|
160 |
+
{"role": "assistant", "content": str(plan_response)}
|
161 |
+
)
|
162 |
+
|
163 |
+
if st.user.is_logged_in:
|
164 |
+
if st.button("🚪 Logout"):
|
165 |
+
st.logout()
|
166 |
+
st.rerun()
|
167 |
+
|
168 |
+
st.markdown(f"## {st.user.email}")
|
169 |
+
SHOWTABS()
|
170 |
+
else:
|
171 |
+
st.info("Please log in to access the Bio Lab")
|
172 |
+
if st.button("Log in"):
|
173 |
+
st.login("auth0")
|
174 |
+
st.stop()
|
175 |
+
|
176 |
+
|
177 |
+
|