todorristov commited on
Commit
204483a
·
1 Parent(s): aa994e3

first test of files

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, ConvNextForImageClassification
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load model and processor from your model repo on the Hub
7
+ model = ConvNextForImageClassification.from_pretrained("todorristov/car_classification_model")
8
+ processor = AutoImageProcessor.from_pretrained("todorristov/car_classification_model")
9
+
10
+ # Define inference function
11
+ def classify_car(image):
12
+ inputs = processor(images=image, return_tensors="pt")
13
+ with torch.no_grad():
14
+ outputs = model(**inputs)
15
+ probs = torch.nn.functional.softmax(outputs.logits, dim=1)
16
+ predicted_class_idx = probs.argmax().item()
17
+ label = model.config.id2label[str(predicted_class_idx)]
18
+ confidence = probs[0][predicted_class_idx].item()
19
+ return f"{label} ({confidence:.2%})"
20
+
21
+ # Gradio UI
22
+ title = "Car Classification (Brand, Model & Year)"
23
+ description = "Upload a car image to identify its brand, model, and year of production."
24
+
25
+ demo = gr.Interface(
26
+ fn=classify_car,
27
+ inputs=gr.Image(type="pil", label="Upload Car Image"),
28
+ outputs=gr.Text(label="Prediction"),
29
+ title=title,
30
+ description=description
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ torchvision
5
+ Pillow