Spaces:
Runtime error
Runtime error
Update app.py
Browse files12342 unmodified lines789101112131415import gradio as grimport requestsfrom PIL import Imagefrom transformers import AutoProcessor, BlipForConditionalGeneration2 unmodified linesprocessor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")def greet(name):return "Hello " + name + "!!"demo = gr.Interface(fn=greet, inputs="text", outputs="text")demo.launch()1232 unmodified lines6789101112131415161718192021222324import requestsfrom PIL import Imagefrom transformers import AutoProcessor, BlipForConditionalGeneration2 unmodified linesprocessor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")# Load your image, DON'T FORGET TO WRITE YOUR IMAGE NAMEimg_path = "YOUR IMAGE NAME.jpeg"# convert it into an RGB formatimage = Image.open(img_path).convert('RGB')# You do not need a question for image captioningtext = "the image of"inputs = processor(images=image, text=text, return_tensors="pt")# Generate a caption for the imageoutputs = model.generate(**inputs, max_length=50)# Decode the generated tokens to textcaption = processor.decode(outputs[0], skip_special_tokens=True)# Print the captionprint(caption)
app.py+14-5