Upload 2 files
Browse files- app.py +33 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Load model and processor from Hugging Face
|
| 7 |
+
model_name = "Muzmmillcoste/finetuned-dermnet"
|
| 8 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 9 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 10 |
+
labels = model.config.id2label
|
| 11 |
+
|
| 12 |
+
# Define prediction function
|
| 13 |
+
def predict(image):
|
| 14 |
+
image = image.convert("RGB") # Ensure correct format
|
| 15 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 16 |
+
with torch.no_grad():
|
| 17 |
+
outputs = model(**inputs)
|
| 18 |
+
logits = outputs.logits
|
| 19 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 20 |
+
predicted_label = labels[str(predicted_class_idx)]
|
| 21 |
+
return f"Predicted Class: {predicted_label}"
|
| 22 |
+
|
| 23 |
+
# Create Gradio Interface
|
| 24 |
+
interface = gr.Interface(
|
| 25 |
+
fn=predict,
|
| 26 |
+
inputs=gr.Image(type="pil"),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="Hair and Skin Disease Classifier",
|
| 29 |
+
description="Upload a scalp or skin image. The model will classify the condition using a fine-tuned Vision Transformer."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Launch app
|
| 33 |
+
interface.launch()
|
requirements.txt
ADDED
|
File without changes
|