Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -4,27 +4,32 @@ from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
|
|
| 4 |
from PIL import Image
|
| 5 |
import json
|
| 6 |
|
|
|
|
|
|
|
| 7 |
MODEL_ID = "Qwen/Qwen2-VL-2B-Instruct"
|
| 8 |
ADAPTER_ID = "hssling/derm-analyzer-adapter"
|
| 9 |
|
| 10 |
print("Starting App Engine...")
|
| 11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 14 |
MODEL_ID,
|
| 15 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 16 |
-
device_map="auto"
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
if ADAPTER_ID:
|
| 20 |
print(f"Loading custom fine-tuned LoRA weights: {ADAPTER_ID}")
|
| 21 |
try:
|
| 22 |
-
model.load_adapter(ADAPTER_ID)
|
| 23 |
print("✅ Adapter loaded successfully over the base Qwen2-VL engine.")
|
| 24 |
except Exception as e:
|
| 25 |
print(f"Failed to load adapter. Using base model. Error: {e}")
|
| 26 |
|
| 27 |
-
def diagnose_skin(image
|
| 28 |
try:
|
| 29 |
if image is None:
|
| 30 |
return json.dumps({"error": "No image provided."})
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import json
|
| 6 |
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
MODEL_ID = "Qwen/Qwen2-VL-2B-Instruct"
|
| 10 |
ADAPTER_ID = "hssling/derm-analyzer-adapter"
|
| 11 |
|
| 12 |
print("Starting App Engine...")
|
| 13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
+
token = os.environ.get("HF_TOKEN")
|
| 15 |
+
|
| 16 |
+
processor = AutoProcessor.from_pretrained(MODEL_ID, token=token)
|
| 17 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 18 |
MODEL_ID,
|
| 19 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 20 |
+
device_map="auto",
|
| 21 |
+
token=token
|
| 22 |
)
|
| 23 |
|
| 24 |
if ADAPTER_ID:
|
| 25 |
print(f"Loading custom fine-tuned LoRA weights: {ADAPTER_ID}")
|
| 26 |
try:
|
| 27 |
+
model.load_adapter(ADAPTER_ID, token=token)
|
| 28 |
print("✅ Adapter loaded successfully over the base Qwen2-VL engine.")
|
| 29 |
except Exception as e:
|
| 30 |
print(f"Failed to load adapter. Using base model. Error: {e}")
|
| 31 |
|
| 32 |
+
def diagnose_skin(image, clinical_notes, temp, max_tokens):
|
| 33 |
try:
|
| 34 |
if image is None:
|
| 35 |
return json.dumps({"error": "No image provided."})
|