[1bdb11]: / app.py

Download this file

161 lines (147 with data), 6.0 kB

  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
"""
Streamlit app for demo.
"""
import streamlit as st
from aitrika.engine.online_aitrika import OnlineAItrika
from aitrika.utils.text_parser import generate_documents
from aitrika.llm.openai import OpenAILLM
from dotenv import load_dotenv
import os
import time
load_dotenv()
st.set_page_config(
page_title="AItrika",
page_icon="images/logo.png",
)
st.title("AItrika 🧪")
def response_generator(query: str):
response = llm.query(query=query)
print(response)
for word in response.split():
yield word + " "
time.sleep(0.05)
def reset_conversation():
st.session_state.conversation = None
st.session_state.chat_history = None
def format_list_to_markdown(items):
markdown_text = ""
if items[0].strip().startswith("**") and items[0].strip().endswith("**"):
markdown_text += f"## {items[0].strip('* ')}\n\n"
items = items[1:]
for item in items:
parts = item.split("\n\n")
if len(parts) >= 2:
for subitem in parts[1:]:
markdown_text += f"- {subitem.strip()}\n"
else:
markdown_text += f"- {item.strip()}\n"
markdown_text = markdown_text.replace('"', "")
markdown_text += "\n"
return markdown_text
pubmed_id = st.text_input("Enter the PubMed ID", placeholder="23747889")
if pubmed_id:
engine = OnlineAItrika(pubmed_id=pubmed_id)
documents = generate_documents(content=engine.extract_abstract())
llm = OpenAILLM(documents=documents, api_key=os.getenv("GROQ_API_KEY"))
with st.expander("Select the information that you want to extract: "):
option = st.selectbox(
" ",
(
"PubMed ID",
"Title",
"Abstract",
"Authors",
"Full text",
"Journal",
"Genes",
"Diseases",
"Species",
"Chemicals",
"Mutations",
"Associations between genes and diseases",
"Results",
"Bibliography",
"Methods",
"Acknowledgements",
"Introduction",
"Paper results",
"Number of participants",
"Characteristics of participants",
),
)
if option == "PubMed ID":
st.markdown("## PubMed ID")
st.write(engine.extract_pubmed_id())
elif option == "Title":
st.markdown("## Title")
st.write(engine.extract_title())
elif option == "Abstract":
st.markdown("## Abstract")
st.write(engine.extract_abstract())
elif option == "Authors":
st.markdown("## Authors")
st.write(engine.extract_authors())
elif option == "Full text":
st.markdown("## Full text")
st.write(engine.extract_full_text())
elif option == "Journal":
st.markdown("## Journal")
st.write(engine.extract_journal())
elif option == "Genes":
st.markdown("## Genes")
st.dataframe(engine.extract_genes(dataframe=True))
st.json(engine.genes())
elif option == "Diseases":
st.markdown("## Diseases")
st.dataframe(engine.extract_diseases(dataframe=True))
st.json(engine.diseases())
elif option == "Associations between genes and diseases":
st.markdown("## Associations between genes and diseases")
st.dataframe(engine.extract_associations(dataframe=True))
st.json(engine.extract_associations())
elif option == "Species":
st.markdown("## Species")
st.dataframe(engine.extract_species(dataframe=True))
st.json(engine.extract_species())
elif option == "Mutations":
st.markdown("## Mutations")
st.dataframe(engine.extract_mutations(dataframe=True))
st.json(engine.extract_mutations())
elif option == "Chemicals":
st.markdown("## Chemicals")
st.dataframe(engine.extract_chemicals(dataframe=True))
st.json(engine.extract_chemicals())
elif option == "Results":
st.markdown("## Results")
st.write(engine.extract_results(llm=llm))
elif option == "Bibliography":
st.markdown("## Bibliography")
st.write(engine.extract_bibliography(llm=llm))
elif option == "Methods":
st.markdown("## Methods")
methods = engine.extract_methods(llm=llm).split("---")
formatted_methods = format_list_to_markdown(methods)
st.markdown(formatted_methods)
elif option == "Acknowledgements":
st.markdown("## Acknowledgements")
st.write(engine.extract_acknowledgements(llm=llm))
elif option == "Introduction":
st.markdown("## Introduction")
st.write(engine.extract_introduction(llm=llm))
elif option == "Number of participants":
st.markdown("## Number of participants")
st.write(engine.extract_number_of_participants(llm=llm))
elif option == "Paper results":
st.markdown("## Paper results")
paper_results = engine.extract_paper_results(llm=llm).split("---")
formatted_paper_results = format_list_to_markdown(paper_results)
st.markdown(formatted_paper_results)
elif option == "Characteristics of participants":
st.markdown("## Characteristics of participants")
characteristics_of_participants = (
engine.extract_characteristics_of_participants(llm=llm).split("---")
)
formatted_characteristics_of_participants = format_list_to_markdown(
characteristics_of_participants
)
st.markdown(formatted_characteristics_of_participants)