AttributeError: 'GPT2LMHeadModel' object has no attribute '__name__'

Hello guys,
I fine-tuned a GPT2 model on some stable diffusion text and I’m trying to create a Gradio space for it but I’m getting this error. The code is mentioned below:-

import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("rexoscare/sd-prompt-generator-gpt-2")
model = AutoModelForCausalLM.from_pretrained("rexoscare/sd-prompt-generator-gpt-2")

input_1 = gr.components.Textbox(placeholder= 'Enter your prompt here...', label = 'Auto Generate Prompt', show_label= True)

iface = gr.Interface(model, inputs= input_1, outputs = 'text', theme = 'huggingface')

Can somebody please help me with this?

Hi @rexoscare, the gr.Interface class is designed to take functions as the argument for the first parameter, not model objects. In other words, you have to wrap a function around the model and pass that into the gr.Interface constructor.

Here’s a GPT-2 example that might be helpful: gpt-2/ at 56208991c8f8df51880336bf2e8f508dee180aaa · gradio-app/gpt-2 · GitHub

Oh yes ! Stupid me. Thank you !

No problem, thanks for asking!