demo
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
-
from peft import PeftModel
|
| 6 |
|
| 7 |
os.environ["ROCR_VISIBLE_DEVICES"] = "0"
|
| 8 |
os.environ["HIP_VISIBLE_DEVICES"] = "0"
|
|
@@ -11,22 +9,7 @@ os.environ["HSA_OVERRIDE_GFX_VERSION"] = "9.4.2"
|
|
| 11 |
BASE_MODEL = "Qwen/Qwen2-1.5B"
|
| 12 |
ADAPTER_PATH = "./outputs"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
|
| 16 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 17 |
-
tokenizer.padding_side = "left"
|
| 18 |
-
|
| 19 |
-
print("Loading model...")
|
| 20 |
-
base = AutoModelForCausalLM.from_pretrained(
|
| 21 |
-
BASE_MODEL,
|
| 22 |
-
dtype=torch.bfloat16,
|
| 23 |
-
device_map="auto",
|
| 24 |
-
trust_remote_code=True,
|
| 25 |
-
)
|
| 26 |
-
model = PeftModel.from_pretrained(base, ADAPTER_PATH)
|
| 27 |
-
model = model.merge_and_unload()
|
| 28 |
-
model.eval()
|
| 29 |
-
print("Ready!")
|
| 30 |
|
| 31 |
EXAMPLES = [
|
| 32 |
["Which artery is occluded in inferior MI with ST elevation in II, III, aVF?",
|
|
@@ -46,29 +29,20 @@ EXAMPLES = [
|
|
| 46 |
def answer(question, opa, opb, opc, opd):
|
| 47 |
if not question.strip():
|
| 48 |
return "Please enter a question."
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
temperature=0.7,
|
| 64 |
-
top_p=0.9,
|
| 65 |
-
top_k=50,
|
| 66 |
-
repetition_penalty=1.3,
|
| 67 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 68 |
-
pad_token_id=tokenizer.eos_token_id,
|
| 69 |
-
)
|
| 70 |
-
new = out[0][inputs["input_ids"].shape[-1]:]
|
| 71 |
-
return tokenizer.decode(new, skip_special_tokens=True)
|
| 72 |
|
| 73 |
CSS = """
|
| 74 |
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:wght@300;400;500&display=swap');
|
|
|
|
| 1 |
import os
|
| 2 |
+
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
os.environ["ROCR_VISIBLE_DEVICES"] = "0"
|
| 6 |
os.environ["HIP_VISIBLE_DEVICES"] = "0"
|
|
|
|
| 9 |
BASE_MODEL = "Qwen/Qwen2-1.5B"
|
| 10 |
ADAPTER_PATH = "./outputs"
|
| 11 |
|
| 12 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
EXAMPLES = [
|
| 15 |
["Which artery is occluded in inferior MI with ST elevation in II, III, aVF?",
|
|
|
|
| 29 |
def answer(question, opa, opb, opc, opd):
|
| 30 |
if not question.strip():
|
| 31 |
return "Please enter a question."
|
| 32 |
+
|
| 33 |
+
# simple mock logic (random-ish but believable)
|
| 34 |
+
import random
|
| 35 |
+
options = [opa, opb, opc, opd]
|
| 36 |
+
letters = ["A", "B", "C", "D"]
|
| 37 |
+
|
| 38 |
+
idx = random.randint(0, 3)
|
| 39 |
+
|
| 40 |
+
return f"""Answer: {letters[idx]}) {options[idx]}
|
| 41 |
+
|
| 42 |
+
Explanation:
|
| 43 |
+
This is a mock demo running without the full model.
|
| 44 |
+
In the real system, a fine-tuned medical LLM analyzes the clinical context
|
| 45 |
+
and selects the most appropriate answer based on learned patterns."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
CSS = """
|
| 48 |
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:wght@300;400;500&display=swap');
|