Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ chat_history = []
|
|
| 26 |
global last_id
|
| 27 |
last_id = None
|
| 28 |
|
| 29 |
-
def chat(prompt, tools):
|
| 30 |
chat_history.append(
|
| 31 |
{"role": "user", "content": prompt}
|
| 32 |
)
|
|
@@ -64,26 +64,29 @@ def chat(prompt, tools):
|
|
| 64 |
)
|
| 65 |
last_id = response.id
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
return "", chat_history, audio_player
|
| 89 |
|
|
@@ -93,18 +96,55 @@ def clear_history():
|
|
| 93 |
global last_id
|
| 94 |
last_id = None
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
with gr.Blocks() as forest:
|
| 97 |
gr.Markdown(
|
| 98 |
"""
|
| 99 |
-
# Chat with OpenAI 04-mini
|
| 100 |
-
|
| 101 |
-
or choose a pre-set molecule from the list to auto-populate a question. You cans use the \
|
| 102 |
-
CafChem tools to generate analogues of a hit molecule for hit expansion or find some \
|
| 103 |
-
ADME properties of a molecule.
|
| 104 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
|
|
|
| 108 |
|
| 109 |
chatbot = gr.Chatbot()
|
| 110 |
|
|
@@ -113,12 +153,12 @@ ADME properties of a molecule.
|
|
| 113 |
chat_btn = gr.Button(value = "Send", scale = 0)
|
| 114 |
elitas_voice = gr.HTML()
|
| 115 |
|
| 116 |
-
|
| 117 |
clear = gr.ClearButton([msg, chatbot])
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
clear.click(clear_history)
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|
|
|
|
| 26 |
global last_id
|
| 27 |
last_id = None
|
| 28 |
|
| 29 |
+
def chat(prompt, tools, voice_choice):
|
| 30 |
chat_history.append(
|
| 31 |
{"role": "user", "content": prompt}
|
| 32 |
)
|
|
|
|
| 64 |
)
|
| 65 |
last_id = response.id
|
| 66 |
|
| 67 |
+
if voice_choice = "On":
|
| 68 |
+
elita_text = response.output_text
|
| 69 |
+
|
| 70 |
+
voice_settings = {
|
| 71 |
+
"stability": 0.37,
|
| 72 |
+
"similarity_boost": 0.90,
|
| 73 |
+
"style": 0.0,
|
| 74 |
+
"speed": 1.05
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
audio_stream = elevenlabs.text_to_speech.convert(
|
| 78 |
+
text = elita_text,
|
| 79 |
+
voice_id = 'vxO9F6g9yqYJ4RsWvMbc',
|
| 80 |
+
model_id = 'eleven_multilingual_v2',
|
| 81 |
+
output_format='mp3_44100_128',
|
| 82 |
+
voice_settings=voice_settings
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
audio_converted = b"".join(audio_stream)
|
| 86 |
+
audio = base64.b64encode(audio_converted).decode("utf-8")
|
| 87 |
+
audio_player = f'<audio src="data:audio/mpeg;base64,{audio}" controls autoplay></audio>'
|
| 88 |
+
else:
|
| 89 |
+
audio_player = ''
|
| 90 |
|
| 91 |
return "", chat_history, audio_player
|
| 92 |
|
|
|
|
| 96 |
global last_id
|
| 97 |
last_id = None
|
| 98 |
|
| 99 |
+
def voice_from_file(file_name):
|
| 100 |
+
audio_file = file_name
|
| 101 |
+
with open(audio_file, 'rb') as audio_bytes:
|
| 102 |
+
audio = base64.b64encode(audio_bytes.read()).decode("utf-8")
|
| 103 |
+
audio_player = f'<audio src="data:audio/mpeg;base64,{audio}" controls autoplay></audio>'
|
| 104 |
+
return audio_player
|
| 105 |
+
|
| 106 |
+
def prot_workflow():
|
| 107 |
+
elita_text = "Starting with a protein, try searching for Uniprot IDs, followed by Chembl IDs. \
|
| 108 |
+
Then you can look for bioactive molecules for each Chembl ID. You can also search for crystal structures \
|
| 109 |
+
in the PDB and get titles of those structures, sequences, numbers of chains, and small molecules in the structure. \
|
| 110 |
+
Generate novel bioactive molecules based on a protein Chembl ID using a GPT, or predict an IC50 for a molecule \
|
| 111 |
+
based on a protein Chembl ID using a gradient-boosting model."
|
| 112 |
+
messages = [{'role': 'assistant', 'content': elita_text}]
|
| 113 |
+
audio_player = voice_from_file('protein_chat.mp3')
|
| 114 |
+
return audio_player, messages
|
| 115 |
+
|
| 116 |
+
def prot_accordions():
|
| 117 |
+
elita_text = 'Try queries like: find UNIPROT IDs for the protein MAOB; find PDB IDs for MAOB; how many chains \
|
| 118 |
+
are in the PDB structure 4A7G; find PDB IDs matching the protein MAOB; list the bioactive molecules for the CHEMBL \
|
| 119 |
+
ID CHEMBL2039; dock the molecule CCCC(F) in the protein DRD2; predict the IC50 value for CCCC(F) based on the CHEMBL \
|
| 120 |
+
ID CHEMBL2039; or generate novel molecules based on the CHEMBL ID CHEMBL2039.'
|
| 121 |
+
messages = [{'role': 'assistant', 'content': elita_text}]
|
| 122 |
+
audio_player = voice_from_file('protein.mp3')
|
| 123 |
+
return audio_player, messages
|
| 124 |
+
|
| 125 |
with gr.Blocks() as forest:
|
| 126 |
gr.Markdown(
|
| 127 |
"""
|
| 128 |
+
# Chat with MoDrAg! OpenAI 04-mini can tap into Modrag through an MCP and use all of your favourite drug design tools.
|
| 129 |
+
- Currently using the tools below:
|
|
|
|
|
|
|
|
|
|
| 130 |
""")
|
| 131 |
+
with gr.Row():
|
| 132 |
+
with gr.Accordion("Protein Agent - Click to open/close.", open=False)as prot:
|
| 133 |
+
gr.Markdown('''
|
| 134 |
+
- Find Uniprot IDs for a protein/gene name.
|
| 135 |
+
- report the number of bioactive molecules for a protein, organized by Chembl ID.
|
| 136 |
+
- report the SMILES and IC50 values of bioactive molecules for a particular Chembl ID.
|
| 137 |
+
- find protein sequences, report number fo chains.
|
| 138 |
+
- find small molecules present in a PDB structure.
|
| 139 |
+
- find PDB IDs that match a protein.
|
| 140 |
+
- predict the IC50 value of a small molecule based on a Chembl ID.
|
| 141 |
+
- generate novel molecules based on a Chembl ID.
|
| 142 |
+
''')
|
| 143 |
+
workflow = gr.Button(value = "Sample Workflow")
|
| 144 |
|
| 145 |
+
with gr.Row():
|
| 146 |
+
tools = gr.Radio(choices = ["Yes", "No"],label="Use CafChem tools?",interactive=True, value = "Yes", scale = 2)
|
| 147 |
+
voice_choice = gr.Radio(choices = ['On', 'Off'],label="Audio Voice Response?", interactive=True, value='Off', scale = 2)
|
| 148 |
|
| 149 |
chatbot = gr.Chatbot()
|
| 150 |
|
|
|
|
| 153 |
chat_btn = gr.Button(value = "Send", scale = 0)
|
| 154 |
elitas_voice = gr.HTML()
|
| 155 |
|
|
|
|
| 156 |
clear = gr.ClearButton([msg, chatbot])
|
| 157 |
|
| 158 |
+
chat_btn.click(chat, [msg, tools, voice_choice], [msg, chatbot, elitas_voice])
|
| 159 |
+
msg.submit(chat, [msg, tools, voice_choice], [msg, chatbot, elitas_voice])
|
| 160 |
+
workflow.click(prot_workflow, outputs=[elitas_voice, chatbot])
|
| 161 |
+
prot.expand(prot_accordions, outputs = [elitas_voice, chatbot])
|
| 162 |
clear.click(clear_history)
|
| 163 |
|
| 164 |
if __name__ == "__main__":
|