Saicharan21 commited on
Commit
ba1d189
·
verified ·
1 Parent(s): f810385

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +15 -16
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 h in history:
38
- msgs.append({"role":"user","content":str(h[0])})
39
- msgs.append({"role":"assistant","content":str(h[1])})
 
 
 
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: " + str(e)
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
- chatbot = gr.Chatbot(label="CardioLab AI", height=450)
69
- msg = gr.Textbox(label="Ask anything about CardioLab research", placeholder="e.g. How does the TGT measure thrombogenicity?", lines=2)
70
- with gr.Row():
71
- send = gr.Button("Send", variant="primary")
72
- clear = gr.Button("Clear Chat")
73
- def respond(message, history):
74
- reply = chat(message, history)
75
- history.append((message, reply))
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)