File size: 10,303 Bytes
b61c416
2e88125
d14c18c
 
9eff8c1
db741c8
2e88125
 
 
 
 
d14c18c
 
fdc7bcd
d14c18c
 
 
bebef8d
658485c
d14c18c
 
 
 
 
658485c
2e88125
b61c416
c3ebcce
7b64d1a
 
36e092b
 
b61c416
dc54ab3
7b64d1a
 
 
 
 
 
 
 
db741c8
b61c416
 
74bc027
7b64d1a
1e012c1
1bd1714
 
4727ea5
6e5ebdb
 
 
1bd1714
 
 
 
 
 
 
 
3517598
02107f0
cb68362
 
 
 
 
972abe5
cb68362
f57bc74
1ef2976
d14c18c
c721e0e
d14c18c
dc54ab3
 
 
 
 
 
 
 
 
972abe5
73b31c5
 
 
 
972abe5
73b31c5
972abe5
73b31c5
9508f6d
12a0dd5
 
 
9508f6d
 
2761d63
9508f6d
bc044e2
73b31c5
972abe5
73b31c5
 
 
 
 
972abe5
73b31c5
 
 
bc044e2
73b31c5
 
 
 
 
bbff065
0179efc
 
 
 
 
 
 
 
7dce95f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0179efc
 
 
 
 
 
 
1bd1714
0179efc
 
 
 
 
2c8859a
73b31c5
0179efc
2c8859a
 
 
 
1ef2976
d14c18c
2c8859a
 
2e88125
 
ea91c1b
2e88125
2c8859a
 
 
2e88125
2c8859a
6e5ebdb
2e88125
0179efc
 
 
 
 
 
 
b61c416
1bd1714
02107f0
4727ea5
c55a531
252c545
1bd1714
4727ea5
 
 
d461ae3
1bd1714
7b64d1a
252c545
5bd7198
 
 
95e6877
5bd7198
 
 
 
 
 
 
 
 
 
2e88125
 
5bd7198
2e88125
 
6e5ebdb
 
 
fcfbdc8
 
 
 
 
 
 
 
6e5ebdb
 
 
db741c8
 
06d0d70
 
 
611f0a6
06d0d70
 
 
 
 
 
f1aa6aa
611f0a6
06d0d70
 
 
 
 
 
db741c8
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import streamlit as st 
import requests
import os
from gliner import GLiNER
#from auth import authenticator

tok=os.getenv("TOK")




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(border=True):
                                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(user_input)

                                    if projectname == None:
                                        st.markdown(":orange-badge[⚠️Set Projectname]")
                                    else:
                                        
                                        payload={
                                            "uid":st.user.email ,
                                            "pid":projectname,
                                            "target":Target_Identification(bio_input) 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)

                                        
                                            
                                        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()
                    
                with st.expander("operations"):
                    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()