File size: 7,691 Bytes
a249ba6
 
b9c182b
dd8b826
1667843
07d335e
 
25dc001
07d335e
c4ee4f0
a0f6368
 
a41e4c6
 
29ca17b
 
e7ea1e9
a41e4c6
 
 
 
29ca17b
25dc001
a832cb6
a249ba6
a832cb6
cea8bef
b87c5b6
033d20e
b87c5b6
a41e4c6
 
 
 
a832cb6
 
07d335e
 
dd8b826
d99b48d
b9c182b
d99b48d
b9c182b
 
 
 
 
9c4b208
b9c182b
 
07d335e
 
d99b48d
 
 
5964123
d99b48d
 
 
 
 
 
 
 
 
 
 
 
 
 
07d335e
93907f0
07d335e
 
b9c182b
 
 
 
 
 
07d335e
 
 
a41e4c6
29ca17b
b9c182b
a41e4c6
 
 
b9c182b
 
07d335e
 
a41e4c6
b9c182b
a249ba6
07d335e
a249ba6
07d335e
 
a249ba6
07d335e
b9c182b
 
 
 
a249ba6
07d335e
a249ba6
cb03708
93907f0
6999776
912a22e
6999776
 
93907f0
 
 
 
 
cb03708
93907f0
 
 
 
 
 
cb03708
912a22e
 
6999776
 
 
 
 
 
 
 
 
cb03708
07d335e
a249ba6
cb03708
 
 
6e2ebc5
07d335e
93907f0
 
b9c182b
 
cb03708
 
b9c182b
 
25dc001
07d335e
d5b28d0
 
 
 
b9c182b
 
 
d5b28d0
 
 
 
fd28539
d5b28d0
 
 
 
b9c182b
d5b28d0
dd8b826
 
 
 
 
 
 
 
 
 
 
ea08d7a
dd8b826
b9c182b
 
dd8b826
 
 
 
 
 
 
 
231c41d
dd8b826
 
 
 
 
db52738
dd8b826
cdb94e2
b9c182b
dd8b826
 
 
 
db52738
 
cdb94e2
 
 
 
db52738
 
 
b9c182b
db52738
b9c182b
db52738
b9c182b
ea08d7a
db52738
cdb94e2
 
 
b9c182b
9c4b208
 
 
 
 
 
988a46d
 
 
9c4b208
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
import streamlit as st

# st.set_page_config(layout="wide")


from ring import PREF_ORDER_LLMS

from ring import generate_response
from ring import generate_panel_response

from openworm_ai import __version__ as openworm_ai_version

from openworm_ai.utils.llms import OPENAI_LLMS

import socket

__version__ = "0.6.0"


def requires_openai_key(llm_ver):
    return llm_ver in OPENAI_LLMS


col1, col2 = st.columns([3, 1])

with col1:
    st.title("OpenWorm.ai")
    st.markdown(
        "Testing the use of LLMs and other AI technology for _C. elegans_ research and computational modelling of the worm. Part of the [OpenWorm](https://openworm.org) project."
    )
    st.markdown(
        "GUI **v%s** (openworm_ai **v%s**) - Note: this is a work in progress!"
        % (__version__, openworm_ai_version)
    )

with col2:
    st.image("images/OpenWormLogo.png")


tab_corpus, tab_free, tab_panel, tab_pubs, tab_data, tab_model, tab_about = st.tabs(
    [
        "OpenWorm Corpus",
        "Individual LLMs",
        "Panel discussion",
        "Publications",
        "Structured data",
        "Run model",
        "About",
    ]
)


with tab_corpus:
    from corpus_query import run_query

    st.markdown("**Search a (small) corpus of _C. elegans_ literature**")

    with st.form("form_corpus"):
        text = st.text_area(
            "Enter a query:",
            "What are the main types of neurons in the C. elegans pharynx? Give me a list of the specific cells.",
        )

        submitted = st.form_submit_button("Submit")

        if submitted:
            response = run_query(query=text)

            st.info(response)

with tab_free:
    st.markdown("**Ask individual LLMs questions about _C. elegans_**")

    with st.form("form_free"):
        text = st.text_area(
            "Ask a question related to _C. elegans_:",
            "What is the primary role of the C. elegans neuron AVBL?",
        )

        llm_ver = st.selectbox("Which LLM version should I use?", PREF_ORDER_LLMS)

        temperature = st.text_input("Temperature", value=0.1)

        allow_all_topics = "MBP" in socket.gethostname()

        only_celegans = st.checkbox(
            "Only answer questions related to _C. elegans_",
            value=not allow_all_topics,
            disabled=not allow_all_topics,
        )

        submitted = st.form_submit_button("Submit")

        if submitted:
            response = generate_response(text, llm_ver, temperature, only_celegans)

            st.info(response)

with tab_panel:
    st.markdown("**Get a consensus answer across multiple LLMs**")

    with st.form("form_panel"):
        text = st.text_area(
            "Ask a question related to _C. elegans_:",
            "What is the typical length of the worm C. elegans?",
        )

        temperature = st.text_input("Temperature", value=0.1)

        ###Start of Kaan Changes
        # Selectbox to determine which LLM becomes panel lead
        st.markdown(
            "<style> .stRadio> div {gap:30px;} </style>",
            unsafe_allow_html=True,
        )
        panel_lead = st.radio(
            "Which LLM would you like to lead this panel?",
            PREF_ORDER_LLMS,
            horizontal=True,
        )

        # Create checkboxes to determine which LLMs are included in the panel
        st.markdown(
            "<div style='text-align: left; font-size: 14px;'>Which LLMs would you like to attend the panel?</div>",
            unsafe_allow_html=True,
        )
        options = PREF_ORDER_LLMS  # [llm for llm in PREF_ORDER_LLMS if llm !=panel_lead] creates a list of options excluding the chosen panel lead
        selected_options = []

        # Put checkboxes into table arranged 4x2
        for row in range(2):  # 2 rows
            cols = st.columns(4)  # 4 columns in each row
            for col in range(4):  # Iterate over each column
                index = row * 4 + col
                if index < len(options):
                    with cols[col]:
                        selected = st.checkbox(options[index], key=options[index])
                        if selected:
                            selected_options.append(options[index])

        submitted = st.form_submit_button("Submit")

        if len(selected_options) == 1 and panel_lead in selected_options:
            st.markdown("Please choose a panelist that is not the panel lead.")
        elif len(selected_options) == 0:
            st.markdown("Please choose one or more panelists to join the panel lead.")
        elif submitted:
            # Create new list of LLMs that does not include panel lead
            llm_panelists = [llm for llm in selected_options if llm != panel_lead]
            response = generate_panel_response(
                text,
                llm_panelists=llm_panelists,
                llm_panel_chair=panel_lead,
                temperature=temperature,
            )

            st.info(response)

with tab_pubs:
    from publications import find_basis_paper

    st.markdown(
        "**Find literature related to _C. elegans._** Uses: [Semantic Scholar](https://www.semanticscholar.org)"
    )

    with st.form("form_pubs"):
        text = st.text_input("Enter a topic:", "C. elegans locomotion")

        num = st.text_input("Number of results", value=10)

        submitted = st.form_submit_button("Submit")

        if submitted:
            response = find_basis_paper(query=text, result_limit=num)

            st.info(response)


with tab_data:
    st.markdown("**Query structured datasets**")

    with st.form("form_data"):
        from datasources import DS_WORMNEUROATLAS
        from datasources import FORMATS
        from datasources import query_data_source

        text = st.text_area("Which neuron would you like to know about?", "AVBL")

        source = st.selectbox("Select data source to use:", (DS_WORMNEUROATLAS,))
        format = st.selectbox("Return format:", FORMATS)

        submitted = st.form_submit_button("Submit")

        if submitted:
            response = query_data_source(text, source, format)

            st.info(response)


with tab_model:
    st.markdown("**Run a _C. elegans_ cell model**")

    with st.form("form_model"):
        from model import run_model
        from model import MODELS

        text = st.text_area("Current injection level:", "4.1 pA")
        model_to_sim = st.selectbox("Model to simulate", list(MODELS.keys()))

        submitted = st.form_submit_button("Submit")

        if submitted:
            response, traces, events = run_model(text, model_to_sim)
            st.info(response)
            try:
                import matplotlib.pyplot as plt

                fig, ax = plt.subplots()

                for key in sorted(traces.keys()):
                    if key != "t":
                        ts = traces["t"]
                        vs = traces[key]
                        ax.plot(ts, vs, label=key)
                        ax.legend()

                        plt.xlabel("Time (s)")
                        plt.ylabel("(SI units)")

                st.pyplot(fig)
            except Exception as e:
                st.info("There was a problem...\n\n%s" % e)

with tab_about:
    st.markdown('### About "Project Sydney"')
    st.markdown(
        "This is an initiative by the [OpenWorm project](https://openworm.org) to investigate the use of LLMs for interacting with scientific literature and structured datasets related to _C. elegans_."
    )
    st.markdown(
        "See also [https://github.com/openworm/openworm.ai](https://github.com/openworm/openworm.ai)."
    )
    st.markdown("**Work in progress!!** Subject to change/removal without notice!")