Spaces:
Running
Running
import streamlit as st | |
import requests | |
import os | |
from auth import authenticator | |
tok=os.getenv("TOK") | |
def InitSession(): | |
if "username" not in st.session_state: | |
st.session_state.username="" | |
if "projectname" not in st.session_state: | |
st.session_state.projectname="" | |
#if "loggedin" not in st.session_state: | |
# st.session_state.loggedin=False | |
InitSession() | |
name, auth_status, username = authenticator.login('Login', 'main') | |
def APP(): | |
col1,col2=st.columns(2) | |
with col1: | |
st.markdown(""" | |
<h2>new <i style='color:red'>MATTER</i> </h2> | |
""",unsafe_allow_html=True) | |
with col2: | |
st.image("https://pub-e4d20ff4ef334a2894d440ac56d680db.r2.dev/flask.gif",width=80) | |
tab1, tab2, tab3 = st.tabs(["PROTEIN ENGINEERING LAB", "EXECUTED OPERATIONS", "LAB OUTPUT"]) | |
def SHOWTABS(): | |
with tab1: | |
option_map = { | |
0: ":material/pill:", | |
1: ":material/vaccines:", | |
2: ":material/labresearch:", | |
3: ":material/warning:" | |
} | |
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:") | |
with st.form("bio",border=False): | |
uid=None | |
project_name=None | |
with st.expander("settings",icon=":material/settings:"): | |
uid=st.text_input("enter username") | |
project_name=st.text_input("enter project name ") | |
if not uid or not project_name: | |
st.markdown(":orange-badge[⚠️ Set Username and Projectname]") | |
bio_input = st.text_area( | |
"Protein Engineering Query", | |
placeholder="Type your query here." | |
) | |
execute_button=st.form_submit_button("execute") | |
if execute_button: | |
if uid and project_name: # Only process if fields are filled | |
st.session_state.projectname = project_name | |
st.session_state.username = uid | |
payload={ | |
"uid":uid, | |
"pid":project_name, | |
"high_level_bio_query":bio_input | |
} | |
response=requests.post("https://thexforce-combat-backend.hf.space/bio_context_language_plan",json=payload,headers={ | |
"Content-Type":"application/json", | |
"Authorization":f"Bearer {tok}" | |
}) | |
plan_response=response.json() | |
if plan_response.get("status")=="active": | |
st.code(f"{plan_response.get('plan')}", language="python") | |
else: | |
st.warning(">>>Error") | |
else: | |
st.error("Please fill in both username and project name before submitting") | |
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("This Interface lets u specify a high level biological query and execute the pipeline for the end product i.e Vaccine",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 selection==3: | |
st.markdown("<p style='color:white;background-color:orange;font-weight:bold'> This system is running in trial phase </p>",unsafe_allow_html=True) | |
with tab2: | |
st.markdown("### newMATTER Bio Lab Operations") | |
def fetch_ops(): | |
response=requests.get(f"https://thexforce-combat-backend.hf.space/user/operations/{st.session_state.get('username')}",headers={ | |
"Content-Type":"application/json", | |
"Authorization":f"Bearer {tok}" | |
}) | |
useroperations_json=response.json() | |
return useroperations_json | |
userops=fetch_ops() | |
with st.expander("operations"): | |
st.json(userops) | |
with tab3: | |
st.markdown("### newMATTER Bio Lab Outputs") | |
projectname=st.text_input("projectname to look the results for ") | |
if st.button("lookup"): | |
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) | |
base_option_map = { | |
0: ":material/login:", | |
1: ":material/personadd:", | |
} | |
selection = st.pills( | |
"ACCESS", | |
options=base_option_map.keys(), | |
format_func=lambda option: base_option_map[option], | |
selection_mode="single", | |
) | |
if selection==0: | |
if auth_status: | |
SHOWTABS() | |
elif auth_status==False: | |
st.write("login failed , try again") | |
if selection==1: | |
try: | |
if authenticator.register_user('Register'): | |
st.success("User registered successfully!") | |
except Exception as e: | |
st.error(e) | |