Hamna27 commited on
Commit
b2d38fe
·
verified ·
1 Parent(s): 3d0c697

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from prompts import MEDICAL_PROMPT
4
+ from risk_engine import detect_risk
5
+
6
+ print("Loading model...")
7
+
8
+ pipe = pipeline(
9
+ "text-generation",
10
+ model="microsoft/Phi-3-mini-4k-instruct",
11
+ trust_remote_code=True
12
+ )
13
+
14
+ print("Model loaded!")
15
+
16
+
17
+ def analyze(symptoms):
18
+
19
+ risk = detect_risk(symptoms)
20
+
21
+ prompt = MEDICAL_PROMPT.format(
22
+ symptoms=symptoms
23
+ )
24
+
25
+ result = pipe(
26
+ prompt,
27
+ max_new_tokens=250,
28
+ do_sample=True,
29
+ temperature=0.7
30
+ )
31
+
32
+ answer = result[0]["generated_text"]
33
+
34
+ return risk, answer
35
+
36
+
37
+ with gr.Blocks(title="MediGuide AI") as demo:
38
+
39
+ gr.Markdown("""
40
+ # 🩺 MediGuide AI
41
+
42
+ Offline Medical Reasoning Assistant
43
+ for Underserved Communities
44
+ """)
45
+
46
+ symptoms = gr.Textbox(
47
+ lines=5,
48
+ label="Describe Your Symptoms"
49
+ )
50
+
51
+ submit = gr.Button("Analyze")
52
+
53
+ risk_box = gr.Textbox(
54
+ label="Risk Level"
55
+ )
56
+
57
+ output = gr.Textbox(
58
+ label="Medical Guidance",
59
+ lines=15
60
+ )
61
+
62
+ submit.click(
63
+ analyze,
64
+ inputs=symptoms,
65
+ outputs=[risk_box, output]
66
+ )
67
+
68
+ demo.launch()