import io import os import requests from PIL import Image from model import get_caption_model, generate_caption import gradio as gr def get_model(): return get_caption_model() caption_model = get_model() def predict(): captions = [] pred_caption = generate_caption('tmp.jpg', caption_model) captions.append(pred_caption) for _ in range(4): pred_caption = generate_caption('tmp.jpg', caption_model, add_noise=True) if pred_caption not in captions: captions.append(pred_caption) #finalc = ' '.join([str(elem) for elem in captions]) return captions; def launch(inputs): img = Image.open(requests.get(inputs, stream=True).raw) img = img.convert('RGB') img.save('tmp.jpg') o=predict() str1="" for ele in o: str1 += "\n"+ele os.remove('tmp.jpg') return str1 iface = gr.Interface(launch, inputs="text", outputs="text",) iface.launch(debug=True,)