File size: 7,246 Bytes
a249ba6
 
 
b9c182b
dd8b826
25dc001
 
b9c182b
25dc001
83083b0
07d335e
 
a249ba6
25dc001
 
 
07d335e
c4ee4f0
9c4b208
25dc001
a832cb6
a249ba6
a832cb6
 
b9c182b
a832cb6
 
07d335e
 
dd8b826
9c4b208
b9c182b
 
 
 
 
 
 
9c4b208
b9c182b
 
07d335e
 
 
 
 
 
 
 
b9c182b
 
 
 
 
 
07d335e
 
 
b9c182b
 
 
 
07d335e
 
 
 
 
b9c182b
a249ba6
07d335e
a249ba6
07d335e
a249ba6
07d335e
a249ba6
07d335e
b9c182b
 
 
 
 
a249ba6
07d335e
a249ba6
3d0ffa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07d335e
a249ba6
3d0ffa3
 
 
 
 
07d335e
 
3d0ffa3
 
b9c182b
 
3d0ffa3
 
b9c182b
 
25dc001
07d335e
d5b28d0
 
 
 
 
b9c182b
 
 
d5b28d0
 
b9c182b
d5b28d0
 
fd28539
d5b28d0
 
 
 
b9c182b
d5b28d0
dd8b826
 
 
 
 
 
 
 
 
 
 
 
 
ea08d7a
dd8b826
b9c182b
 
dd8b826
 
 
 
 
 
 
 
231c41d
 
 
 
b9c182b
 
 
231c41d
 
 
b9c182b
 
 
 
 
 
 
 
231c41d
 
 
 
 
 
 
 
dd8b826
 
 
 
 
 
 
db52738
dd8b826
cdb94e2
b9c182b
dd8b826
 
 
 
db52738
 
cdb94e2
 
 
 
 
 
db52738
 
 
b9c182b
db52738
b9c182b
db52738
b9c182b
ea08d7a
db52738
cdb94e2
 
 
b9c182b
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
import streamlit
import streamlit as st

# st.set_page_config(layout="wide")

from ring import LLM_GPT35
from ring import LLM_GPT4
from ring import LLM_GPT4o
from ring import LLM_LLAMA2
from ring import LLM_GEMINI
from ring import PREF_ORDER_LLMS


from ring import requires_openai_key
from ring import get_openai_api_key
from ring import generate_response
from ring import generate_panel_response

__version__ = "0.1.9"

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

with col1:
    st.title("Project Sydney")
    st.markdown("**OpenWorm LLM v%s** - work in progress!" % __version__)

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


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


with tab_free:

    st.markdown("**Ask individual LLMs questions**")

    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)

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

        submitted = st.form_submit_button("Submit")

        if requires_openai_key(llm_ver) and not get_openai_api_key():
            st.info("Please add your OpenAI API key to continue.")
        elif 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
        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 columns to be arranged horizontally
        cols = st.columns(len(options))
        for i, option in enumerate(options):
            with cols[i]:
                selected = st.checkbox(option, key=option)
                if selected:
                    selected_options.append(option)

        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 a panelist to join the panel lead.")
        elif requires_openai_key(llm_ver) and not get_openai_api_key():
            st.info("Please add your OpenAI API key to continue.")
        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_corpus:

    from corpus_query import run_query

    st.markdown(
        "**Search a (small) corpus of _C. elegans_ literature** Uses: [paper-qa](https://github.com/whitead/paper-qa)"
    )

    with st.form("form_corpus"):

        text = st.text_input(
            "Enter a query:",
            "What types of ion channels are present in C. elegans neurons?",
        )

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

        submitted = st.form_submit_button("Submit")

        if submitted:
            response = run_query(query=text, llm_ver=llm_ver)

            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 numpy as np
                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("**Work in progress!!** Subject to change/removal without notice!")