Srikar00007 commited on
Commit
07aa29e
Β·
verified Β·
1 Parent(s): 84bc5bc

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +79 -0
  2. best.pt +3 -0
  3. med-gemma.ipynb +1 -0
  4. requirement.txt +6 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
+ from PIL import Image
4
+ from ultralytics import YOLO
5
+ import torch
6
+
7
+ # ----------------------------------------------------
8
+ # βœ… 1. Wound Classification Model (HuggingFace)
9
+ # ----------------------------------------------------
10
+ st.write("⏳ Loading Wound Classification Model...")
11
+ wound_pipe = pipeline("image-classification", model="Hemg/Wound-Image-classification")
12
+
13
+ # ----------------------------------------------------
14
+ # βœ… 2. YOLO Skin Disease Model (Your trained model)
15
+ # ----------------------------------------------------
16
+ st.write("⏳ Loading YOLO Skin Disease Model...")
17
+ yolo_model = YOLO("best.pt")
18
+
19
+ # ----------------------------------------------------
20
+ # βœ… 3. MedGemma 4B LLM (HuggingFace)
21
+ # ----------------------------------------------------
22
+ st.write("⏳ Loading MedGemma LLM...")
23
+ LLM_ID = "google/medgemma-4b-it"
24
+ tokenizer = AutoTokenizer.from_pretrained(LLM_ID)
25
+ chat_model = AutoModelForCausalLM.from_pretrained(
26
+ LLM_ID,
27
+ device_map="auto",
28
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
29
+ )
30
+
31
+ # ----------------------------------------------------
32
+ # βœ… STREAMLIT WEB UI
33
+ # ----------------------------------------------------
34
+ st.title("🩺 Medical Diagnosis + AI Assistant")
35
+ st.write("Upload an image β†’ detect wound + skin disease β†’ ask medical questions.")
36
+
37
+ uploaded_image = st.file_uploader("πŸ“€ Upload Image", type=["jpg", "jpeg", "png"])
38
+
39
+ if uploaded_image:
40
+ img = Image.open(uploaded_image).convert("RGB")
41
+ st.image(img, caption="Uploaded Image", use_column_width=True)
42
+
43
+ st.subheader("πŸ” Detection Results")
44
+
45
+ # βœ… Wound Classification
46
+ wound_pred = wound_pipe(img)[0]
47
+ wound_label = wound_pred["label"]
48
+ wound_conf = round(wound_pred["score"], 3)
49
+ st.write(f"βœ… **Wound Type:** {wound_label} ({wound_conf})")
50
+
51
+ # βœ… YOLO Skin Disease Detection
52
+ yolo_out = yolo_model(img)
53
+
54
+ if len(yolo_out[0].boxes) > 0:
55
+ cls_id = int(yolo_out[0].boxes.cls[0])
56
+ skin_label = yolo_model.names[cls_id]
57
+ st.write(f"βœ… **Skin Disease (YOLO):** {skin_label}")
58
+ else:
59
+ skin_label = "None"
60
+ st.write("βœ… No skin disease detected.")
61
+
62
+ st.subheader("πŸ’¬ Medical AI Chat")
63
+
64
+ user_input = st.text_input("Ask a medical question")
65
+
66
+ if st.button("Ask"):
67
+ prompt = f"""
68
+ Detected wound: {wound_label}
69
+ Detected skin disease: {skin_label}
70
+ User question: {user_input}
71
+
72
+ Respond like a medical expert.
73
+ """
74
+ inputs = tokenizer(prompt, return_tensors="pt").to(chat_model.device)
75
+ outputs = chat_model.generate(**inputs, max_new_tokens=300)
76
+ reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
77
+
78
+ st.write("### βœ… AI Response")
79
+ st.write(reply)
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72db90f81032d76d9ef0e3aaf2f439c7e71afe0eab9a27bc0b821a2a0a1f5686
3
+ size 31704281
med-gemma.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"colab":{"machine_shape":"hm","gpuType":"T4"},"accelerator":"GPU","kaggle":{"accelerator":"gpu","dataSources":[],"dockerImageVersionId":31193,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# βœ… Install dependencies\n!pip install transformers accelerate --quiet\n\n# βœ… Import required libraries\nfrom kaggle_secrets import UserSecretsClient\nfrom huggingface_hub import login\nfrom transformers import AutoTokenizer, AutoModelForCausalLM, pipeline\n\n# βœ… Load your HF token from Kaggle Secrets (make sure secret name = HF_TOKEN)\nuser_secrets = UserSecretsClient()\nhf_token = user_secrets.get_secret(\"HF_TOKEN\")\n\n# βœ… Login to HuggingFace\nlogin(token=hf_token)\n\n# βœ… Model ID (correct one you asked for)\nmodel_id = \"google/medgemma-4b-it\"\n\n# βœ… Load tokenizer\ntokenizer = AutoTokenizer.from_pretrained(\n model_id, \n trust_remote_code=True\n)\n\n# βœ… Load model on GPU\nmodel = AutoModelForCausalLM.from_pretrained(\n model_id,\n device_map=\"auto\",\n torch_dtype=\"auto\",\n trust_remote_code=True\n)\n\n# βœ… Build pipeline\npipe = pipeline(\n \"text-generation\",\n model=model,\n tokenizer=tokenizer,\n max_new_tokens=350,\n temperature=0.25\n)\n\n# βœ… Ask MedGemma a question\nprompt = \"Explain medically in simple terms: What are the symptoms of a heart attack?\"\n\nresult = pipe(prompt)[0][\"generated_text\"]\n\n# βœ… Print output\nprint(\"\\n🧠 MedGemma 4B Response:\\n\")\nprint(result)\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-07T19:39:17.872323Z","iopub.execute_input":"2025-11-07T19:39:17.873021Z","iopub.status.idle":"2025-11-07T19:40:29.668192Z","shell.execute_reply.started":"2025-11-07T19:39:17.872994Z","shell.execute_reply":"2025-11-07T19:40:29.667474Z"}},"outputs":[{"output_type":"display_data","data":{"text/plain":"tokenizer_config.json: 0%| | 0.00/1.16M [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"f537affa494d4a528e5571e0fc446656"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"tokenizer.model: 0%| | 0.00/4.69M [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"25e88d479e1c450c8f2c0a786cc70ab6"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"tokenizer.json: 0%| | 0.00/33.4M [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"0b3ee25e8bef4d168c840de83a555fcc"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"added_tokens.json: 0%| | 0.00/35.0 [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"3a67e6e923f545c485154789bab5609e"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"special_tokens_map.json: 0%| | 0.00/662 [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"a9f0208f98e44e00b2fce86e4e80b97b"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"chat_template.jinja: 0%| | 0.00/1.53k [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"c3fb0e347c8648a2a4f3e0624b0b52bb"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"config.json: 0%| | 0.00/2.47k [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"890472733c164644a63e3f7490f20b51"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"model.safetensors.index.json: 0%| | 0.00/90.6k [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"3d6b5acbb008455abe5679abaa886269"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"Fetching 2 files: 0%| | 0/2 [00:00<?, ?it/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"0dab637538374ed1ba7006d7c45ec0b2"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"model-00001-of-00002.safetensors: 0%| | 0.00/4.96G [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"37ca252578c94d16adcec573cc3c3bf6"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"model-00002-of-00002.safetensors: 0%| | 0.00/3.64G [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"4d2729edb3ef4ab8bb67ee7c8e8688bc"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"0dca30f73a7b4e1c8d2234c068140ce5"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"generation_config.json: 0%| | 0.00/156 [00:00<?, ?B/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"328c1fe30dff4f3282d9573cd1b78b37"}},"metadata":{}},{"name":"stderr","text":"Device set to use cuda:0\n","output_type":"stream"},{"name":"stdout","text":"\n🧠 MedGemma 4B Response:\n\nExplain medically in simple terms: What are the symptoms of a heart attack?\n\nThe symptoms of a heart attack can vary from person to person, and not everyone experiences the same symptoms. However, some common symptoms include:\n\n* **Chest pain or discomfort:** This is the most common symptom. It can feel like pressure, squeezing, fullness, or pain in the center of the chest. The pain may last for more than a few minutes, or it may go away and come back.\n* **Pain or discomfort in other areas of the upper body:** This can include pain or discomfort in one or both arms, the back, neck, jaw, or stomach.\n* **Shortness of breath:** This can occur with or without chest pain.\n* **Cold sweat:** Breaking out in a cold sweat for no apparent reason.\n* **Nausea or vomiting:** Feeling sick to your stomach or throwing up.\n* **Lightheadedness or dizziness:** Feeling faint or unsteady.\n* **Unexplained fatigue:** Feeling unusually tired or weak.\n\nIt's important to note that women are more likely than men to experience some of these symptoms, such as shortness of breath, nausea/vomiting, and back or jaw pain.\n\nIf you experience any of these symptoms, especially if they are new or unusual for you, it's important to seek medical attention immediately. A heart attack is a serious medical emergency, and prompt treatment can save your life.\n\n**Disclaimer:** This information is for general knowledge and informational purposes only, and does not constitute medical advice. It is essential to consult with a qualified healthcare professional for any health concerns or before making any decisions related to your health or treatment.\nExplain medically in simple terms: What are the symptoms of a heart\n","output_type":"stream"}],"execution_count":3}]}
requirement.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ torch
3
+ transformers
4
+ ultralytics
5
+ pillow
6
+ accelerate