Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -34,15 +34,18 @@ def chat(message, history):
|
|
| 34 |
try:
|
| 35 |
client = Groq(api_key=GROQ_KEY)
|
| 36 |
msgs = [{"role":"system","content":"You are CardioLab AI from SJSU Biomedical Engineering built on Biomni Stanford SNAP Lab. Expert in MHV MCL PIV TGT uPAD CKD FSI COMSOL. Remember the full conversation. Never invent paper URLs.\n\n"+KNOWHOW}]
|
| 37 |
-
for
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
pubmed = get_pubmed(message)
|
| 41 |
msgs.append({"role":"user","content":message})
|
| 42 |
resp = client.chat.completions.create(model="llama-3.3-70b-versatile",messages=msgs,max_tokens=600)
|
| 43 |
return resp.choices[0].message.content + pubmed
|
| 44 |
except Exception as e:
|
| 45 |
-
return "Error: "
|
| 46 |
|
| 47 |
def piv_tool(velocity, shear, hr):
|
| 48 |
v = "HIGH - stenosis risk" if float(velocity)>2.0 else "NORMAL"
|
|
@@ -65,18 +68,14 @@ with gr.Blocks(title="CardioLab AI - SJSU") as demo:
|
|
| 65 |
gr.Markdown("Open Source: github.com/pranatechsol/Cardio-Lab-Ai")
|
| 66 |
with gr.Tab("Research Chat"):
|
| 67 |
gr.Markdown("### Chat with memory like ChatGPT for CardioLab research")
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
return "", history
|
| 77 |
-
send.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 78 |
-
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 79 |
-
clear.click(lambda: [], None, chatbot)
|
| 80 |
with gr.Tab("PIV Analysis"):
|
| 81 |
gr.Markdown("### Analyze PIV flow data from Mock Circulatory Loop")
|
| 82 |
v = gr.Number(label="Max Velocity m/s", value=1.8)
|
|
|
|
| 34 |
try:
|
| 35 |
client = Groq(api_key=GROQ_KEY)
|
| 36 |
msgs = [{"role":"system","content":"You are CardioLab AI from SJSU Biomedical Engineering built on Biomni Stanford SNAP Lab. Expert in MHV MCL PIV TGT uPAD CKD FSI COMSOL. Remember the full conversation. Never invent paper URLs.\n\n"+KNOWHOW}]
|
| 37 |
+
for item in history:
|
| 38 |
+
if isinstance(item, dict):
|
| 39 |
+
msgs.append({"role":item["role"],"content":item["content"]})
|
| 40 |
+
elif isinstance(item, (list,tuple)) and len(item)==2:
|
| 41 |
+
if item[0]: msgs.append({"role":"user","content":str(item[0])})
|
| 42 |
+
if item[1]: msgs.append({"role":"assistant","content":str(item[1])})
|
| 43 |
pubmed = get_pubmed(message)
|
| 44 |
msgs.append({"role":"user","content":message})
|
| 45 |
resp = client.chat.completions.create(model="llama-3.3-70b-versatile",messages=msgs,max_tokens=600)
|
| 46 |
return resp.choices[0].message.content + pubmed
|
| 47 |
except Exception as e:
|
| 48 |
+
return "Error: "+str(e)
|
| 49 |
|
| 50 |
def piv_tool(velocity, shear, hr):
|
| 51 |
v = "HIGH - stenosis risk" if float(velocity)>2.0 else "NORMAL"
|
|
|
|
| 68 |
gr.Markdown("Open Source: github.com/pranatechsol/Cardio-Lab-Ai")
|
| 69 |
with gr.Tab("Research Chat"):
|
| 70 |
gr.Markdown("### Chat with memory like ChatGPT for CardioLab research")
|
| 71 |
+
gr.ChatInterface(
|
| 72 |
+
fn=chat,
|
| 73 |
+
chatbot=gr.Chatbot(height=450, label="CardioLab AI"),
|
| 74 |
+
textbox=gr.Textbox(placeholder="Ask anything about CardioLab research...", lines=2, label="Your message"),
|
| 75 |
+
submit_btn="Send",
|
| 76 |
+
clear_btn="Clear Chat",
|
| 77 |
+
title="CardioLab Research Assistant"
|
| 78 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
with gr.Tab("PIV Analysis"):
|
| 80 |
gr.Markdown("### Analyze PIV flow data from Mock Circulatory Loop")
|
| 81 |
v = gr.Number(label="Max Velocity m/s", value=1.8)
|