Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -13,13 +13,22 @@ KNOWHOW = ('SJSU CardioLab: '
|
|
| 13 |
'Equipment: Heska HT5 hematology analyzer time-resolved PIV Tygon tubing Arduino Uno.')
|
| 14 |
|
| 15 |
CSS = (
|
| 16 |
-
'.gradio-container { background: #0a0f1e !important;
|
| 17 |
-
'
|
| 18 |
-
'.
|
| 19 |
-
'.
|
| 20 |
-
'
|
| 21 |
-
'
|
| 22 |
-
'h1 { color: #e63946 !important; font-size: 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
def get_pubmed(query, n=5):
|
|
@@ -53,7 +62,7 @@ def quick_search(query):
|
|
| 53 |
pubmed = get_pubmed(query, n=8)
|
| 54 |
scholar = get_scholar(query, n=5)
|
| 55 |
result = 'PAPERS FOR: ' + query + chr(10)+chr(10)
|
| 56 |
-
result += 'PUBMED (
|
| 57 |
result += 'SEMANTIC SCHOLAR:'+chr(10)+scholar
|
| 58 |
return result
|
| 59 |
|
|
@@ -91,7 +100,12 @@ def piv_tool(velocity, shear, hr):
|
|
| 91 |
def tgt_tool(tat,pf12,hemo,platelets,time):
|
| 92 |
risk=sum([float(tat)>15,float(pf12)>2.0,float(hemo)>50,float(platelets)<150])
|
| 93 |
r='HIGH THROMBOGENIC RISK' if risk>=3 else 'MODERATE RISK' if risk>=2 else 'LOW RISK'
|
| 94 |
-
return 'TIME: '+str(time)+' min'+chr(10)+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
def upad_tool(r,g,b):
|
| 97 |
c=max(0,round(0.02*(float(r)-float(b))-0.5,2))
|
|
@@ -106,7 +120,7 @@ with gr.Blocks(title='CardioLab AI', css=CSS) as demo:
|
|
| 106 |
gr.Markdown('# CardioLab AI')
|
| 107 |
|
| 108 |
with gr.Tabs():
|
| 109 |
-
with gr.Tab('Chat'):
|
| 110 |
chatbot = gr.Chatbot(label='', height=500)
|
| 111 |
with gr.Row():
|
| 112 |
msg_box = gr.Textbox(placeholder='Ask anything about CardioLab research...', label='', lines=2, scale=4)
|
|
@@ -117,14 +131,14 @@ with gr.Blocks(title='CardioLab AI', css=CSS) as demo:
|
|
| 117 |
msg_box.submit(research_chat, inputs=[msg_box, chatbot], outputs=[msg_box, chatbot])
|
| 118 |
clear_btn.click(lambda: ([], ''), outputs=[chatbot, msg_box])
|
| 119 |
|
| 120 |
-
with gr.Tab('Paper Search'):
|
| 121 |
search_input = gr.Textbox(placeholder='e.g. mechanical heart valve thrombogenicity', label='Research topic')
|
| 122 |
search_btn = gr.Button('Search Papers', variant='primary')
|
| 123 |
search_output = gr.Textbox(label='Results', lines=20)
|
| 124 |
search_btn.click(quick_search, inputs=search_input, outputs=search_output)
|
| 125 |
search_input.submit(quick_search, inputs=search_input, outputs=search_output)
|
| 126 |
|
| 127 |
-
with gr.Tab('PIV Analysis'):
|
| 128 |
with gr.Row():
|
| 129 |
with gr.Column():
|
| 130 |
v=gr.Number(label='Max Velocity m/s', value=1.8)
|
|
@@ -133,7 +147,7 @@ with gr.Blocks(title='CardioLab AI', css=CSS) as demo:
|
|
| 133 |
piv_out=gr.Textbox(label='Result', lines=5)
|
| 134 |
gr.Button('Analyze PIV', variant='primary').click(piv_tool,inputs=[v,s,h],outputs=piv_out)
|
| 135 |
|
| 136 |
-
with gr.Tab('TGT Results'):
|
| 137 |
t1=gr.Number(label='TAT ng/mL', value=18)
|
| 138 |
t2=gr.Number(label='PF1.2 nmol/L', value=2.5)
|
| 139 |
t3=gr.Number(label='Free Hemoglobin mg/L', value=60)
|
|
@@ -142,7 +156,7 @@ with gr.Blocks(title='CardioLab AI', css=CSS) as demo:
|
|
| 142 |
out2=gr.Textbox(label='Result', lines=8)
|
| 143 |
gr.Button('Analyze TGT', variant='primary').click(tgt_tool,inputs=[t1,t2,t3,t4,t5],outputs=out2)
|
| 144 |
|
| 145 |
-
with gr.Tab('uPAD CKD'):
|
| 146 |
r=gr.Number(label='R value', value=210)
|
| 147 |
g=gr.Number(label='G value', value=140)
|
| 148 |
b=gr.Number(label='B value', value=80)
|
|
|
|
| 13 |
'Equipment: Heska HT5 hematology analyzer time-resolved PIV Tygon tubing Arduino Uno.')
|
| 14 |
|
| 15 |
CSS = (
|
| 16 |
+
'body, .gradio-container { background: #0a0f1e !important; }'
|
| 17 |
+
'.tabs { background: #0d1b3e !important; border-bottom: 2px solid #e63946 !important; }'
|
| 18 |
+
'.tab-nav button { color: #a8b2d8 !important; background: transparent !important; font-size: 1em !important; font-weight: 600 !important; padding: 10px 20px !important; border: none !important; border-bottom: 3px solid transparent !important; }'
|
| 19 |
+
'.tab-nav button.selected { color: #e63946 !important; border-bottom: 3px solid #e63946 !important; background: transparent !important; }'
|
| 20 |
+
'.tab-nav button:hover { color: #ffffff !important; background: #1a2744 !important; }'
|
| 21 |
+
'h1, h2, h3, h4, label, p, span { color: #e2e8f0 !important; }'
|
| 22 |
+
'h1 { color: #e63946 !important; font-size: 2.8em !important; font-weight: 900 !important; text-align: center !important; padding: 25px 0 !important; letter-spacing: 2px !important; }'
|
| 23 |
+
'textarea, input[type=number], input[type=text] { background: #1a2744 !important; color: #e2e8f0 !important; border: 1px solid #4361ee !important; border-radius: 8px !important; }'
|
| 24 |
+
'textarea::placeholder { color: #6b7db3 !important; }'
|
| 25 |
+
'.gr-button { border-radius: 8px !important; font-weight: 700 !important; padding: 10px 20px !important; }'
|
| 26 |
+
'button.primary { background: linear-gradient(135deg, #e63946 0%, #c1121f 100%) !important; color: white !important; border: none !important; }'
|
| 27 |
+
'button.secondary { background: #1d3461 !important; color: #a8b2d8 !important; border: 1px solid #4361ee !important; }'
|
| 28 |
+
'.message.bot { background: #1a2744 !important; border: 1px solid #2d4a8a !important; color: #e2e8f0 !important; border-radius: 12px !important; }'
|
| 29 |
+
'.message.user { background: linear-gradient(135deg, #e63946, #c1121f) !important; color: white !important; border-radius: 12px !important; }'
|
| 30 |
+
'.block { background: #0d1b3e !important; border: 1px solid #1e3a6e !important; border-radius: 12px !important; }'
|
| 31 |
+
'.chatbot { background: #0d1b3e !important; border: 1px solid #2d4a8a !important; border-radius: 12px !important; }'
|
| 32 |
)
|
| 33 |
|
| 34 |
def get_pubmed(query, n=5):
|
|
|
|
| 62 |
pubmed = get_pubmed(query, n=8)
|
| 63 |
scholar = get_scholar(query, n=5)
|
| 64 |
result = 'PAPERS FOR: ' + query + chr(10)+chr(10)
|
| 65 |
+
result += 'PUBMED (verified links):'+chr(10)+pubmed+chr(10)+chr(10)
|
| 66 |
result += 'SEMANTIC SCHOLAR:'+chr(10)+scholar
|
| 67 |
return result
|
| 68 |
|
|
|
|
| 100 |
def tgt_tool(tat,pf12,hemo,platelets,time):
|
| 101 |
risk=sum([float(tat)>15,float(pf12)>2.0,float(hemo)>50,float(platelets)<150])
|
| 102 |
r='HIGH THROMBOGENIC RISK' if risk>=3 else 'MODERATE RISK' if risk>=2 else 'LOW RISK'
|
| 103 |
+
return ('TIME: '+str(time)+' min'+chr(10)+
|
| 104 |
+
'TAT: '+str(tat)+(' - HIGH' if float(tat)>15 else ' - NORMAL')+chr(10)+
|
| 105 |
+
'PF1.2: '+str(pf12)+(' - HIGH' if float(pf12)>2.0 else ' - NORMAL')+chr(10)+
|
| 106 |
+
'HEMOGLOBIN: '+str(hemo)+(' - HIGH' if float(hemo)>50 else ' - NORMAL')+chr(10)+
|
| 107 |
+
'PLATELETS: '+str(platelets)+(' - LOW' if float(platelets)<150 else ' - NORMAL')+chr(10)+chr(10)+
|
| 108 |
+
'OVERALL: '+r)
|
| 109 |
|
| 110 |
def upad_tool(r,g,b):
|
| 111 |
c=max(0,round(0.02*(float(r)-float(b))-0.5,2))
|
|
|
|
| 120 |
gr.Markdown('# CardioLab AI')
|
| 121 |
|
| 122 |
with gr.Tabs():
|
| 123 |
+
with gr.Tab('💬 Chat'):
|
| 124 |
chatbot = gr.Chatbot(label='', height=500)
|
| 125 |
with gr.Row():
|
| 126 |
msg_box = gr.Textbox(placeholder='Ask anything about CardioLab research...', label='', lines=2, scale=4)
|
|
|
|
| 131 |
msg_box.submit(research_chat, inputs=[msg_box, chatbot], outputs=[msg_box, chatbot])
|
| 132 |
clear_btn.click(lambda: ([], ''), outputs=[chatbot, msg_box])
|
| 133 |
|
| 134 |
+
with gr.Tab('🔍 Paper Search'):
|
| 135 |
search_input = gr.Textbox(placeholder='e.g. mechanical heart valve thrombogenicity', label='Research topic')
|
| 136 |
search_btn = gr.Button('Search Papers', variant='primary')
|
| 137 |
search_output = gr.Textbox(label='Results', lines=20)
|
| 138 |
search_btn.click(quick_search, inputs=search_input, outputs=search_output)
|
| 139 |
search_input.submit(quick_search, inputs=search_input, outputs=search_output)
|
| 140 |
|
| 141 |
+
with gr.Tab('📊 PIV Analysis'):
|
| 142 |
with gr.Row():
|
| 143 |
with gr.Column():
|
| 144 |
v=gr.Number(label='Max Velocity m/s', value=1.8)
|
|
|
|
| 147 |
piv_out=gr.Textbox(label='Result', lines=5)
|
| 148 |
gr.Button('Analyze PIV', variant='primary').click(piv_tool,inputs=[v,s,h],outputs=piv_out)
|
| 149 |
|
| 150 |
+
with gr.Tab('🩸 TGT Results'):
|
| 151 |
t1=gr.Number(label='TAT ng/mL', value=18)
|
| 152 |
t2=gr.Number(label='PF1.2 nmol/L', value=2.5)
|
| 153 |
t3=gr.Number(label='Free Hemoglobin mg/L', value=60)
|
|
|
|
| 156 |
out2=gr.Textbox(label='Result', lines=8)
|
| 157 |
gr.Button('Analyze TGT', variant='primary').click(tgt_tool,inputs=[t1,t2,t3,t4,t5],outputs=out2)
|
| 158 |
|
| 159 |
+
with gr.Tab('🧪 uPAD CKD'):
|
| 160 |
r=gr.Number(label='R value', value=210)
|
| 161 |
g=gr.Number(label='G value', value=140)
|
| 162 |
b=gr.Number(label='B value', value=80)
|