After trying pretty much everything I gave the latest Grok2 a spin at converting my old malfunctioning Python/Gradio code which no longer adheres to syntax innovations and feature adds within python and gradio.
Grok2 in my opinion is the only one which could do this. Examine below instant one shot win by Grok2 with gradio! Greatest thing about it is it shows references via tweet so you can find where the intelligence was added so Grok2 is using modern syntax and unlike OpenAI and Anthropic, it produces innovative modern results aware of recent innovation.
Grok2 for the win I guess!
Tried a straw man example shown below which fails on others but works on Grok2:
Original which fails now if you upgrade Gradio:
import gradio as gr
from fastai.vision.all import *
import skimage
learn = load_learner('characters.pkl')
labels = learn.dls.vocab
def predict(img):
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
title = "Video Game Character Classifier"
# description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
#article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
examples = ['ellie.jpg','arthur.jpg','kratos.jpg','ellielou.jpg']
interpretation='default'
enable_queue=True
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(128, 128)),outputs=gr.outputs.Label(),title=title,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
Second Grok2 prompt (first switched to blocks shown below).
Grok2's second shot with examples of errors gave working code and also tweet references!!
import gradio as gr
from fastai.vision.all import *
import skimage
learn = load_learner('characters.pkl')
labels = learn.dls.vocab
def predict(img):
pred, pred_idx, probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
title = "Video Game Character Classifier"
examples = ['ellie.jpg', 'arthur.jpg', 'kratos.jpg', 'ellielou.jpg']
# Updated Gradio Interface with new syntax
with gr.Blocks() as demo:
gr.Markdown("# " + title)
# Use width and height instead of shape
image_input = gr.Image(width=128, height=128)
label_output = gr.Label()
# Create submit button
submit_btn = gr.Button("Classify")
submit_btn.click(fn=predict, inputs=image_input, outputs=label_output)
# Adding examples
gr.Examples(examples, inputs=image_input, outputs=label_output, fn=predict)
demo.launch()