Spaces:
Runtime error
Runtime error
Matt Grannell commited on
Commit ·
831f30b
1
Parent(s): 94e3c71
Fix imports, model loading and dependencies
Browse files- app.py +19 -2
- requirements.txt +8 -1
app.py
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import base64
|
| 3 |
import io
|
| 4 |
from PIL import Image
|
| 5 |
-
from
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
classifier = MedImageInsight(
|
| 8 |
-
model_dir=
|
| 9 |
vision_model_name="medimageinsigt-v1.0.0.pt",
|
| 10 |
language_model_name="language_model.pth"
|
| 11 |
)
|
| 12 |
classifier.load_model()
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def analyze(image: Image.Image, labels_str: str):
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
import gradio as gr
|
| 4 |
import base64
|
| 5 |
import io
|
| 6 |
from PIL import Image
|
| 7 |
+
from huggingface_hub import snapshot_download
|
| 8 |
|
| 9 |
+
# Download the full lion-ai/MedImageInsights repo (code + model weights)
|
| 10 |
+
# Cached after first run — won't re-download on restarts
|
| 11 |
+
print("Downloading MedImageInsights repo...")
|
| 12 |
+
repo_path = snapshot_download("lion-ai/MedImageInsights")
|
| 13 |
+
print(f"Downloaded to: {repo_path}")
|
| 14 |
+
|
| 15 |
+
# Make the repo's Python modules importable
|
| 16 |
+
sys.path.insert(0, repo_path)
|
| 17 |
+
|
| 18 |
+
from medimageinsightmodel import MedImageInsight # noqa: E402
|
| 19 |
+
|
| 20 |
+
model_dir = os.path.join(repo_path, "2024.09.27")
|
| 21 |
+
|
| 22 |
+
print("Loading model...")
|
| 23 |
classifier = MedImageInsight(
|
| 24 |
+
model_dir=model_dir,
|
| 25 |
vision_model_name="medimageinsigt-v1.0.0.pt",
|
| 26 |
language_model_name="language_model.pth"
|
| 27 |
)
|
| 28 |
classifier.load_model()
|
| 29 |
+
print("Model ready.")
|
| 30 |
|
| 31 |
|
| 32 |
def analyze(image: Image.Image, labels_str: str):
|
requirements.txt
CHANGED
|
@@ -1,4 +1,11 @@
|
|
| 1 |
-
git+https://huggingface.co/lion-ai/MedImageInsights
|
| 2 |
huggingface_hub
|
| 3 |
Pillow
|
| 4 |
torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
huggingface_hub
|
| 2 |
Pillow
|
| 3 |
torch
|
| 4 |
+
pandas
|
| 5 |
+
timm
|
| 6 |
+
transformers
|
| 7 |
+
einops
|
| 8 |
+
ftfy
|
| 9 |
+
sentencepiece
|
| 10 |
+
fvcore
|
| 11 |
+
mup
|