Spaces:
Runtime error
Runtime error
hamdanhh07
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
|
|
|
|
|
|
|
|
|
| 4 |
extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
|
| 5 |
model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch16-224")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/hamdan07/UltraSound-Lung"
|
| 8 |
headers = {"Authorization": "Bearer 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"}
|
| 9 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
| 5 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import requests
|
| 8 |
extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
|
| 9 |
model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch16-224")
|
| 10 |
|
| 11 |
+
dataset = load_dataset("hamdan07/UltraSound-lung")
|
| 12 |
+
image = Image.open(requests.get(dataset, stream=True).raw)
|
| 13 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch16-224')
|
| 14 |
+
model = ViTForImageClassification.from_pretrained('google/vit-base-patch16-224')
|
| 15 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
| 16 |
+
outputs = model(**inputs)
|
| 17 |
+
logits = outputs.logits
|
| 18 |
+
predicted_class_idx = logits.argmax(-1).item()
|
| 19 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
| 20 |
API_URL = "https://api-inference.huggingface.co/models/hamdan07/UltraSound-Lung"
|
| 21 |
headers = {"Authorization": "Bearer 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"}
|
| 22 |
|