Spaces:
Sleeping
Sleeping
File size: 1,738 Bytes
528a96f 8ec1acd ca8ddcf 528a96f 454c914 8e13729 d87e79e 454c914 528a96f d9c4377 454c914 d9c4377 454c914 ca8ddcf 454c914 d9c4377 454c914 d9c4377 59c7d1b 454c914 ca8ddcf 58d7915 d87e79e ca8ddcf 454c914 ca8ddcf 27709c6 ca8ddcf d9c4377 ca8ddcf d9c4377 ca8ddcf d9c4377 454c914 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import gradio as gr
from transformers import pipeline
from datasets import load_dataset
def get_dataset_examples():
dataset = load_dataset("Avmromanov/tripoexamples")
train_data = dataset['train']
example_ids = [0, 3, 6]
examples = []
for i in example_ids:
example = train_data[i]
examples.append(example['image'])
return examples
def identify_car(image):
if image.mode != 'RGB':
image = image.convert('RGB')
predictions = car_classifier(image)
result_text = "Car Identification Results:\n\n"
top_5 = predictions[:5]
for i, pred in enumerate(top_5, 1):
label = pred['label'].replace('_', ' ').title()
confidence = pred['score']
result_text += f"{i}. {label}: {confidence:.2%}\n"
result_text += f"\nMost likely: **{top_5[0]['label'].replace('_', ' ').title()}** " \
f"(confidence: {top_5[0]['score']:.2%})"
return result_text
car_classifier = pipeline("image-classification", model="dima806/car_models_image_detection")
dataset_examples = get_dataset_examples()
with gr.Blocks() as demo:
gr.Markdown("# Car Identifier with My Dataset")
gr.Markdown("Using examples from: **Avmromanov/tripoexamples**")
with gr.Row():
with gr.Column():
image_input = gr.Image(label="Upload Car Photo", type="pil")
identify_btn = gr.Button("Identify Car", variant="primary")
with gr.Column():
output_text = gr.Textbox(label="Results", lines=10)
gr.Examples(
examples=dataset_examples,
inputs=image_input,
outputs=output_text,
fn=identify_car,
cache_examples=True
)
demo.launch()
|