Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,134 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = ""
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
-
demo = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
def health_monitoring(bp_sys, bp_dia, temp, heart_rate, spo2):
|
| 4 |
+
messages = []
|
| 5 |
+
|
| 6 |
+
if bp_sys > 140 or bp_dia > 90:
|
| 7 |
+
messages.append("⚠️ Umuvuduko w’amaraso uri hejuru cyane.")
|
| 8 |
+
elif bp_sys < 90 or bp_dia < 60:
|
| 9 |
+
messages.append("⚠️ Umuvuduko w’amaraso uri hasi cyane.")
|
| 10 |
+
else:
|
| 11 |
+
messages.append("✅ Umuvuduko w’amaraso uri mu rugero rwiza.")
|
| 12 |
+
|
| 13 |
+
if temp > 38:
|
| 14 |
+
messages.append("⚠️ Ubushyuhe bw’umubiri buri hejuru, hashobora kuba indwara.")
|
| 15 |
+
elif temp < 36:
|
| 16 |
+
messages.append("⚠️ Ubushyuhe bw’umubiri buri hasi cyane.")
|
| 17 |
+
else:
|
| 18 |
+
messages.append("✅ Ubushyuhe bw’umubiri buri mu rugero.")
|
| 19 |
+
|
| 20 |
+
if heart_rate > 100:
|
| 21 |
+
messages.append("⚠️ Umuvuduko w’imitima uri hejuru.")
|
| 22 |
+
elif heart_rate < 60:
|
| 23 |
+
messages.append("⚠️ Umuvuduko w’imitima uri hasi.")
|
| 24 |
+
else:
|
| 25 |
+
messages.append("✅ Umuvuduko w’imitima uri mu rugero rwiza.")
|
| 26 |
+
|
| 27 |
+
if spo2 < 95:
|
| 28 |
+
messages.append("⚠️ Oxygen saturation iri hasi, bishobora kuba ikibazo.")
|
| 29 |
+
else:
|
| 30 |
+
messages.append("✅ Oxygen saturation iri mu rugero rwiza.")
|
| 31 |
+
|
| 32 |
+
alerts = [m for m in messages if m.startswith("⚠️")]
|
| 33 |
+
if alerts:
|
| 34 |
+
messages.append("\n⚠️ Inama: Gana muganga vuba.")
|
| 35 |
+
else:
|
| 36 |
+
messages.append("\n✅ Uruhare rwawe ni rwiza, komereza aho.")
|
| 37 |
+
|
| 38 |
+
return "\n".join(messages)
|
| 39 |
|
| 40 |
+
def adjust_value(value, delta, min_val, max_val):
|
| 41 |
+
new_val = value + delta
|
| 42 |
+
if new_val < min_val:
|
| 43 |
+
new_val = min_val
|
| 44 |
+
if new_val > max_val:
|
| 45 |
+
new_val = max_val
|
| 46 |
+
return new_val
|
| 47 |
|
| 48 |
+
with gr.Blocks() as demo:
|
| 49 |
+
gr.Markdown("## Healthcare Monitoring System with Adjustment Buttons")
|
| 50 |
+
|
| 51 |
+
bp_sys = gr.Slider(50, 200, step=1, label="Umuvuduko w'amaraso (Systolic)", value=120)
|
| 52 |
+
bp_dia = gr.Slider(30, 130, step=1, label="Umuvuduko w'amaraso (Diastolic)", value=80)
|
| 53 |
+
temp = gr.Slider(30.0, 42.0, step=0.1, label="Ubushyuhe bw'umubiri (°C)", value=36.5)
|
| 54 |
+
heart_rate = gr.Slider(30, 150, step=1, label="Umuvuduko w'imitima (bpm)", value=75)
|
| 55 |
+
spo2 = gr.Slider(70, 100, step=1, label="Oxygen Saturation (%)", value=98)
|
| 56 |
+
|
| 57 |
+
output = gr.Textbox(label="Ibisubizo bya System", lines=12)
|
| 58 |
+
|
| 59 |
+
# Function to update all values and output after adjustments
|
| 60 |
+
def update_all(bp_sys_val, bp_dia_val, temp_val, heart_rate_val, spo2_val):
|
| 61 |
+
return health_monitoring(bp_sys_val, bp_dia_val, temp_val, heart_rate_val, spo2_val)
|
| 62 |
+
|
| 63 |
+
# Buttons for bp_sys
|
| 64 |
+
bp_sys_inc = gr.Button("+")
|
| 65 |
+
bp_sys_dec = gr.Button("-")
|
| 66 |
+
# Buttons for bp_dia
|
| 67 |
+
bp_dia_inc = gr.Button("+")
|
| 68 |
+
bp_dia_dec = gr.Button("-")
|
| 69 |
+
# Buttons for temp
|
| 70 |
+
temp_inc = gr.Button("+")
|
| 71 |
+
temp_dec = gr.Button("-")
|
| 72 |
+
# Buttons for heart_rate
|
| 73 |
+
heart_rate_inc = gr.Button("+")
|
| 74 |
+
heart_rate_dec = gr.Button("-")
|
| 75 |
+
# Buttons for spo2
|
| 76 |
+
spo2_inc = gr.Button("+")
|
| 77 |
+
spo2_dec = gr.Button("-")
|
| 78 |
+
|
| 79 |
+
# Layout
|
| 80 |
+
with gr.Row():
|
| 81 |
+
gr.Column([bp_sys, bp_sys_dec, bp_sys_inc])
|
| 82 |
+
gr.Column([bp_dia, bp_dia_dec, bp_dia_inc])
|
| 83 |
+
with gr.Row():
|
| 84 |
+
gr.Column([temp, temp_dec, temp_inc])
|
| 85 |
+
gr.Column([heart_rate, heart_rate_dec, heart_rate_inc])
|
| 86 |
+
gr.Column([spo2, spo2_dec, spo2_inc])
|
| 87 |
+
|
| 88 |
+
# Connect buttons to update sliders and output
|
| 89 |
+
bp_sys_inc.click(
|
| 90 |
+
lambda val: adjust_value(val, 1, 50, 200), bp_sys, bp_sys)
|
| 91 |
+
bp_sys_dec.click(
|
| 92 |
+
lambda val: adjust_value(val, -1, 50, 200), bp_sys, bp_sys)
|
| 93 |
+
|
| 94 |
+
bp_dia_inc.click(
|
| 95 |
+
lambda val: adjust_value(val, 1, 30, 130), bp_dia, bp_dia)
|
| 96 |
+
bp_dia_dec.click(
|
| 97 |
+
lambda val: adjust_value(val, -1, 30, 130), bp_dia, bp_dia)
|
| 98 |
+
|
| 99 |
+
temp_inc.click(
|
| 100 |
+
lambda val: adjust_value(val, 0.1, 30.0, 42.0), temp, temp)
|
| 101 |
+
temp_dec.click(
|
| 102 |
+
lambda val: adjust_value(val, -0.1, 30.0, 42.0), temp, temp)
|
| 103 |
+
|
| 104 |
+
heart_rate_inc.click(
|
| 105 |
+
lambda val: adjust_value(val, 1, 30, 150), heart_rate, heart_rate)
|
| 106 |
+
heart_rate_dec.click(
|
| 107 |
+
lambda val: adjust_value(val, -1, 30, 150), heart_rate, heart_rate)
|
| 108 |
+
|
| 109 |
+
spo2_inc.click(
|
| 110 |
+
lambda val: adjust_value(val, 1, 70, 100), spo2, spo2)
|
| 111 |
+
spo2_dec.click(
|
| 112 |
+
lambda val: adjust_value(val, -1, 70, 100), spo2, spo2)
|
| 113 |
+
|
| 114 |
+
# When any slider changes, update output
|
| 115 |
+
for slider in [bp_sys, bp_dia, temp, heart_rate, spo2]:
|
| 116 |
+
slider.change(
|
| 117 |
+
fn=update_all,
|
| 118 |
+
inputs=[bp_sys, bp_dia, temp, heart_rate, spo2],
|
| 119 |
+
outputs=output
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# Also update output when buttons clicked by triggering slider change
|
| 123 |
+
for slider in [bp_sys, bp_dia, temp, heart_rate, spo2]:
|
| 124 |
+
slider.change(
|
| 125 |
+
fn=update_all,
|
| 126 |
+
inputs=[bp_sys, bp_dia, temp, heart_rate, spo2],
|
| 127 |
+
outputs=output
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
# Show initial values result
|
| 131 |
+
output.value = health_monitoring(120, 80, 36.5, 75, 98)
|
| 132 |
|
| 133 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|