File size: 527 Bytes
b492424
a845b90
b492424
a845b90
 
b492424
a845b90
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import gradio as gr
from transformers import pipeline
import os

# Ensure this environment variable is set correctly
hf_token = os.getenv("HF_TOKEN")

# Load the model using pipeline (which gives more control and better error handling)
classifier = pipeline("image-classification", model="lamrin8224/oxford_flowers_image_detection", token=hf_token)

def predict(img):
    result = classifier(img)
    return {r['label']: r['score'] for r in result}

gr.Interface(fn=predict, inputs="image", outputs="label").launch(share=True)