plantopia / app.py
lamrin8224's picture
Update app.py
a845b90 verified
raw
history blame contribute delete
527 Bytes
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)