reshma-05 commited on
Commit
62d15f6
·
verified ·
1 Parent(s): 93cdd3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -1
app.py CHANGED
@@ -1,6 +1,55 @@
 
 
 
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- import os
4
  import gradio as gr
5
  from transformers import AutoModelForCausalLM, AutoTokenizer
6
  import torch
 
1
+ import os
2
+ import gradio as gr
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
+ # Use Hugging Face token (set in Space settings)
6
+ token = os.environ.get("HF_TOKEN")
7
+
8
+ model_id = "ibm-granite/granite-3.3-2b-instruct"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_id, token=token)
10
+ model = AutoModelForCausalLM.from_pretrained(model_id, token=token)
11
+
12
+ def generate_response(prompt):
13
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
14
+ outputs = model.generate(**inputs, max_new_tokens=200)
15
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+
17
+ def disease_prediction(symptoms):
18
+ prompt = f"Patient has symptoms: {symptoms}. What are the possible conditions?"
19
+ return generate_response(prompt)
20
+
21
+ def treatment_plan(condition):
22
+ prompt = f"Suggest treatment for {condition}"
23
+ return generate_response(prompt)
24
+
25
+ def health_analytics(vitals):
26
+ prompt = f"Analyze vitals: {vitals}"
27
+ return generate_response(prompt)
28
+
29
+ def patient_chat(query):
30
+ return generate_response(query)
31
+
32
+ with gr.Blocks() as demo:
33
+ gr.Markdown("# 🏥 HealthAI")
34
+ with gr.Tab("Disease Prediction"):
35
+ inp = gr.Textbox(label="Symptoms")
36
+ out = gr.Textbox()
37
+ gr.Button("Predict").click(disease_prediction, inp, out)
38
+ with gr.Tab("Treatment Plan"):
39
+ inp2 = gr.Textbox(label="Condition")
40
+ out2 = gr.Textbox()
41
+ gr.Button("Get Plan").click(treatment_plan, inp2, out2)
42
+ with gr.Tab("Health Analytics"):
43
+ inp3 = gr.Textbox(label="Vitals")
44
+ out3 = gr.Textbox()
45
+ gr.Button("Analyze").click(health_analytics, inp3, out3)
46
+ with gr.Tab("Patient Chat"):
47
+ inp4 = gr.Textbox(label="Ask a question")
48
+ out4 = gr.Textbox()
49
+ gr.Button("Ask").click(patient_chat, inp4, out4)
50
+
51
+ demo.launch()
52
 
 
53
  import gradio as gr
54
  from transformers import AutoModelForCausalLM, AutoTokenizer
55
  import torch