Spaces:
Sleeping
Sleeping
Commit ·
70d0cfa
1
Parent(s): 7d764e2
added api endpoint for frontend app
Browse files1234567891011121314151617181920import gradio as grfrom transformers import pipelinefrom PIL import Image # ✅ make sure PIL is imported# Load your modelmodel = pipeline("image-classification", model="wellCh4n/tomato-leaf-disease-classification-vit")def classify(image):if not isinstance(image, Image.Image):image = Image.fromarray(image) # fallback, just in caseresult = model(image)return result[0]['label'] # return top labelgr.Interface(fn=classify,inputs=gr.Image(type="pil"),outputs="label",title="Tomato Leaf Disease Analyzer",description="Upload a tomato leaf image to detect the disease.").launch()12345678910111213141516171819202122232425import gradio as grfrom transformers import pipelinefrom PIL import Image# Load your modelmodel = pipeline("image-classification", model="wellCh4n/tomato-leaf-disease-classification-vit")# Define the prediction functiondef classify(image):if not isinstance(image, Image.Image):image = Image.fromarray(image)result = model(image)return result[0]['label'] # You can also return full result if you want scores# Define the interfaceapp = gr.Interface(fn=classify,inputs=gr.Image(type="pil"),outputs="label",title="Tomato Leaf Disease Analyzer",description="Upload a tomato leaf image to detect the disease.")# 🚀 Enable both UI and APIapp.launch(show_api=True)
app.py+10-5