Junaidb's picture
Update ui.py
4efcdd2 verified
raw
history blame
11.5 kB
import streamlit as st
import requests
import os
from gliner import GLiNER
#from auth import authenticator
from streamlit_autorefresh import st_autorefresh
tok=os.getenv("TOK")
"----------------------------------------------"
st_autorefresh(interval=5000,key="volter")
"----------------------------------------------"
def Target_Identification(userinput):
model = GLiNER.from_pretrained("Ihor/gliner-biomed-bi-small-v1.0")
labels = ["Protein"]
entities = model.predict_entities(userinput, labels, threshold=0.5)
result={}
for entity in entities:
if entity["label"] =="Protein":
return entity["text"]
def APP():
tab_map = {
0: "BIO ENGINEERING LAB @newMATTER",
#1: "EXECUTED OPERATIONS @newMATTER",
}
tab_selection=st.pills(
"TABS",
options=tab_map.keys(),
format_func=lambda option:tab_map[option],
selection_mode="single"
)
def SHOWTABS():
if tab_selection == 0 :
option_map = {
0: "@OriginAI Nanobody Engineering:",
#1: "@OriginAI Ops",
#2: "Information"
}
selection = st.pills(
"BIOLOGICS",
options=option_map.keys(),
format_func=lambda option: option_map[option],
selection_mode="single",
)
#match selection:
if selection == 0:
st.markdown("<p style='color:white;background-color:orange;font-weight:bold'> Nanobody [CANCER targeted]</p>",unsafe_allow_html=True)
#with st.expander("info"):
#st.info("This Interface lets u specify a high level biological query (Protein Engineering Query) and execute the pipeline for the end product i.e Engineered Nanobody",icon=":material/info:")
projects=[]
projectname=None
#with st.form("bio",border=False):
#project_name=None
def scan_for_project_availability(user_id):
request_url=f"https://thexforce-combat-backend.hf.space/{user_id}/projects"
response=requests.get(request_url,headers={
"Content-Type":"application/json",
"Authorization":f"Bearer {tok}"
})
response_json=response.json()
pros=response_json.get("projects")
for pro in pros:
projects.append(pro.get("project"))
#st.session_state.projects=projects
#project_details=response.json()
#if project_details.get("projectname") !=None or project_details.get("projectname") !="":
# st.session_state.projectname = project_details.get("projectname")
scan_for_project_availability(st.user.email)
if len(projects) > 0 :
option = st.selectbox(
"selectproject",
projects
)
projectname = option
#if projectname == "":
# with st.expander("Set up the project before proceeding."):
# projectname = st.text_input("Provide project name > ")
elif len(projects) == 0:
p_name=st.text_input("enter project name : ")
projectname=p_name
#bio_input = st.text_area(
# "Protein Engineering Query",
# placeholder="Type your query here."
#)
#execute_button=st.form_submit_button("execute")
bio_input = st.chat_input(" Ready for Action ! ")
"""----------------experimental--------------------"""
@st.cache_data(ttl=10)
def fetch_ops():
response=requests.get(f"https://thexforce-combat-backend.hf.space/user/operations/{st.user.email}",
headers={
"Content-Type":"application/json",
"Authorization":f"Bearer {tok}"
})
useroperations_json=response.json()
return useroperations_json
"""---------------experimental-----------------------"""
with st.container():
if len(st.session_state.messages) > 0:
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
if bio_input:
st.session_state.messages.append({"role":"user","content":bio_input})
with st.chat_message("user"):
st.markdown(bio_input)
if projectname == None or projectname == "":
st.markdown(":orange-badge[⚠️Set Projectname]")
else:
identified_target=Target_Identification(bio_input)
st.warning(f"TARGET IDENTIFIED IS :{identified_target}")
payload={
"uid":st.user.email ,
"pid":projectname,
"target":identified_target or None,
"high_level_bio_query":bio_input
}
response=requests.post("https://thexforce-combat-backend.hf.space/application_layer_agent",json=payload,headers={
"Content-Type":"application/json",
"Authorization":f"Bearer {tok}"
})
plan_response=response.json()
#st.markdown(f"## {plan_response}")
with st.chat_message("assistant"):
st.markdown(plan_response)
"---------------------experimental--------------------------------"
fetch_ops_response=fetch_ops()
if fetch_ops_response.get("exp") != None:
for op in fetch_ops_response.get("exp"):
with st.chat_message("assistant"):
st.markdown(op.get("operation"))
st.markdown(op.get("output"))
"------------------------------------------------------------------"
st.session_state.messages.append({"role":"assistant","content":plan_response})
#if selection == 1:
#st.markdown("<p style='color:white;background-color:orange;font-weight:bold'>Vaccine [Supported] </p>",unsafe_allow_html=True)
#with st.expander("info"):
#st.info("",icon=":material/info:")
#st.code("coming soon")
#if selection ==2:
#st.markdown("<p style='color:white;background-color:orange;font-weight:bold'>Operation Details </p>",unsafe_allow_html=True)
#if tab_selection == 1:
#st.markdown("### ORIGINAI Bio Lab Operations")
#@st.cache_data(ttl=10)
#def fetch_ops():
#response=requests.get(f"https://thexforce-combat-backend.hf.space/user/operations/{st.user.email}",headers={
# "Content-Type":"application/json",
# "Authorization":f"Bearer {tok}"
#})
#useroperations_json=response.json()
#return useroperations_json
#userops=fetch_ops()
## st.json(userops)
'''
response=requests.get(
f"https://thexforce-combat-backend.hf.space/{st.session_state.get('username')}/{projectname}/individual/experiment",
headers={
"Content-Type":"application/json",
"Authorization":f"Bearer {tok}"
})
ie=response.json()
st.json(ie)
'''
if st.user.is_logged_in:
if st.button("🚪 Logout"):
st.logout()
st.rerun()
#Then show the main UI
st.markdown(f"## {st.user.email}")
SHOWTABS()
else:
#Show login when NOT logged in
st.info("Please log in to access the Bio Lab")
if st.button("Log in"):
st.login("auth0")
st.stop()