Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,12 @@ import os
|
|
| 27 |
from rdkit import RDConfig
|
| 28 |
from rdkit.Chem.Features.ShowFeats import _featColors as featColors
|
| 29 |
from rdkit.Chem.FeatMaps import FeatMaps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
fdef = AllChem.BuildFeatureFactory(os.path.join(RDConfig.RDDataDir,'BaseFeatures.fdef'))
|
| 32 |
|
|
@@ -357,8 +363,10 @@ def parser_node(state: State) -> State:
|
|
| 357 |
props_string = state["props_string"]
|
| 358 |
query_task = state["query_task"]
|
| 359 |
|
| 360 |
-
prompt = f'Using only the information provided in the CONTEXT below, answer the QUERY_TASK.\n
|
| 361 |
-
QUERY_TASK
|
|
|
|
|
|
|
| 362 |
CONTEXT: {props_string}.\n '
|
| 363 |
|
| 364 |
res = chat_model.invoke(prompt)
|
|
@@ -472,7 +480,28 @@ def PropAgent(task, smiles, reference):
|
|
| 472 |
else:
|
| 473 |
img = Image.new('RGB', (250, 250), color = (255, 255, 255))
|
| 474 |
|
| 475 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
|
| 477 |
with gr.Blocks(fill_height=True) as forest:
|
| 478 |
gr.Markdown('''
|
|
@@ -492,9 +521,10 @@ with gr.Blocks(fill_height=True) as forest:
|
|
| 492 |
with gr.Column():
|
| 493 |
props = gr.Textbox(label="Agent results: ", lines=20 )
|
| 494 |
pic = gr.Image(label="Molecule")
|
|
|
|
| 495 |
|
| 496 |
|
| 497 |
-
calc_btn.click(PropAgent, inputs = [task, smiles, ref], outputs = [props, pic])
|
| 498 |
-
task.submit(PropAgent, inputs = [task, smiles, ref], outputs = [props, pic])
|
| 499 |
|
| 500 |
forest.launch(debug=False, mcp_server=True)
|
|
|
|
| 27 |
from rdkit import RDConfig
|
| 28 |
from rdkit.Chem.Features.ShowFeats import _featColors as featColors
|
| 29 |
from rdkit.Chem.FeatMaps import FeatMaps
|
| 30 |
+
from elevenlabs.client import ElevenLabs
|
| 31 |
+
from elevenlabs import stream
|
| 32 |
+
|
| 33 |
+
eleven_key = os.getenv("eleven_key")
|
| 34 |
+
|
| 35 |
+
elevenlabs = ElevenLabs(api_key=eleven_key)
|
| 36 |
|
| 37 |
fdef = AllChem.BuildFeatureFactory(os.path.join(RDConfig.RDDataDir,'BaseFeatures.fdef'))
|
| 38 |
|
|
|
|
| 363 |
props_string = state["props_string"]
|
| 364 |
query_task = state["query_task"]
|
| 365 |
|
| 366 |
+
prompt = f'Using only the information provided in the CONTEXT below, answer the QUERY_TASK.\n \
|
| 367 |
+
Your answer must:\n Directly address the QUERY_TASK.\n Use only facts found in the CONTEXT \
|
| 368 |
+
(do not invent information).\n Be concise, precise and logically consistent.\n End your answer with a "#" \
|
| 369 |
+
QUERY_TASK: {query_task}.\n \
|
| 370 |
CONTEXT: {props_string}.\n '
|
| 371 |
|
| 372 |
res = chat_model.invoke(prompt)
|
|
|
|
| 480 |
else:
|
| 481 |
img = Image.new('RGB', (250, 250), color = (255, 255, 255))
|
| 482 |
|
| 483 |
+
elita_text = replies[-1]
|
| 484 |
+
|
| 485 |
+
voice_settings = {
|
| 486 |
+
"stability": 0.37,
|
| 487 |
+
"similarity_boost": 0.90,
|
| 488 |
+
"style": 0.0,
|
| 489 |
+
"speed": 1.05
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
audio_stream = elevenlabs.text_to_speech.convert(
|
| 493 |
+
text = elita_text,
|
| 494 |
+
voice_id = 'G5KS88IIzHIX1ogRxdrA',
|
| 495 |
+
model_id = 'eleven_multilingual_v2',
|
| 496 |
+
output_format='mp3_44100_128',
|
| 497 |
+
voice_settings=voice_settings
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
audio_converted = b"".join(audio_stream)
|
| 501 |
+
audio = base64.b64encode(audio_converted).decode("utf-8")
|
| 502 |
+
audio_player = f'<audio src="data:audio/mpeg;base64,{audio}" controls autoplay></audio>'
|
| 503 |
+
|
| 504 |
+
return replies[-1], img, audio_player
|
| 505 |
|
| 506 |
with gr.Blocks(fill_height=True) as forest:
|
| 507 |
gr.Markdown('''
|
|
|
|
| 521 |
with gr.Column():
|
| 522 |
props = gr.Textbox(label="Agent results: ", lines=20 )
|
| 523 |
pic = gr.Image(label="Molecule")
|
| 524 |
+
voice = gr.HTML()
|
| 525 |
|
| 526 |
|
| 527 |
+
calc_btn.click(PropAgent, inputs = [task, smiles, ref], outputs = [props, pic, voice])
|
| 528 |
+
task.submit(PropAgent, inputs = [task, smiles, ref], outputs = [props, pic, voice])
|
| 529 |
|
| 530 |
forest.launch(debug=False, mcp_server=True)
|