Spaces:
Sleeping
Sleeping
Update app.py
Browse files64 unmodified lines65666768697071727374757677787980812 unmodified lines8485868788899091923 unmodified lines9697989910010110210364 unmodified linesdef caption_random_image():# AA: pick random row - from DFsample = df.sample(1).iloc[0]# BB: Pick a random image path - image from folder##img_path = random.choice(image_paths)# BB: Load into PIL - image from folder - image from folder##image = Image.open(img_path).convert("RGB")# AA: Image - for DFimage = sample["image"]# Unconditional image captioninginputs = processor(image, return_tensors="pt")2 unmodified linescaption_eng = processor.decode(out[0], skip_special_tokens=True)# Translate caption from English to Spanish##trans_inputs = trans_tokenizer.encode(caption_eng, return_tensors="pt")##trans_out = trans_model.generate(trans_inputs)##caption_es = trans_tokenizer.decode(trans_out[0], skip_special_tokens=True)return image, caption_eng, caption_es3 unmodified linesinputs=None,outputs=[gr.Image(type="pil", label="Random Image"),gr.Textbox(label="Caption (English)")##gr.Textbox(label="Caption (Spanish)")],title="Image Captioning (with English to Spanish translation)",description="Selects a random image (from either the local folder or henryscheible/coco data subset); generates a BLIP caption; then translates the (English) caption to Spanish."64 unmodified lines65666768697071727374757677787980812 unmodified lines8485868788899091923 unmodified lines9697989910010110210364 unmodified linesdef caption_random_image():# AA: pick random row - from DF##sample = df.sample(1).iloc[0]# BB: Pick a random image path - image from folderimg_path = random.choice(image_paths)# BB: Load into PIL - image from folder - image from folderimage = Image.open(img_path).convert("RGB")# AA: Image - for DF##image = sample["image"]# Unconditional image captioninginputs = processor(image, return_tensors="pt")2 unmodified linescaption_eng = processor.decode(out[0], skip_special_tokens=True)# Translate caption from English to Spanishtrans_inputs = trans_tokenizer.encode(caption_eng, return_tensors="pt")trans_out = trans_model.generate(trans_inputs)caption_es = trans_tokenizer.decode(trans_out[0], skip_special_tokens=True)return image, caption_eng, caption_es3 unmodified linesinputs=None,outputs=[gr.Image(type="pil", label="Random Image"),gr.Textbox(label="Caption (English)"),gr.Textbox(label="Caption (Spanish)")],title="Image Captioning (with English to Spanish translation)",description="Selects a random image (from either the local folder or henryscheible/coco data subset); generates a BLIP caption; then translates the (English) caption to Spanish."
app.py+9-9