Spaces:
Runtime error
Runtime error
Commit ·
a0727b2
1
Parent(s): 87045f7
Update app.py
Browse files1234567891011121314151617181920212223242519 unmodified lines45464748495051525354from PIL import Imagefrom transformers import CLIPProcessor, CLIPModelimport gradio as gr# Initialize CLIP model and processorprocessor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")def image_similarity(image: Image.Image, positive_prompt: str, negative_prompts: str):# Split the negative prompts string into a list of promptsnegative_prompts_list = negative_prompts.split(";")# Combine positive and negative prompts into one listprompts = [positive_prompt.strip()] + [np.strip() for np in negative_prompts_list]# ... rest of the codeinputs = processor(text=prompts,images=image,return_tensors="pt",padding=True)19 unmodified linesgr.components.Textbox(label="Probability for Positive Prompt")],title="Engagify's Image Action Detection",description="[Author: Ibrahim Hasani] This Method uses CLIP-VIT [Version: BASE-PATCH-16] to determine if an action is being performed in an image or not. (Binary Classifier). It contrasts an Action against multiple negative labels. Ensure the prompts accurately describe the desired detection.",live=False,theme=gr.themes.Monochrome(),)interface.launch()12345678910111213141516171819202122232425262728293019 unmodified lines50515253from PIL import Imagefrom transformers import CLIPProcessor, CLIPModelimport gradio as grimport torchvision.transforms as transforms# Initialize CLIP model and processorprocessor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")def image_similarity(image: Image.Image, positive_prompt: str, negative_prompts: str):# Convert the PIL Image to a tensor and preprocesstransform = transforms.Compose([transforms.Resize((224, 224)),transforms.ToTensor(),transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),])image_tensor = transform(image).unsqueeze(0) # Add batch dimension# Split the negative prompts string into a list of promptsnegative_prompts_list = negative_prompts.split(";")# Combine positive and negative prompts into one listprompts = [positive_prompt.strip()] + [np.strip() for np in negative_prompts_list]# Process prompts and image tensorinputs = processor(text=prompts,images=image_tensor,return_tensors="pt",padding=True)19 unmodified linesgr.components.Textbox(label="Probability for Positive Prompt")],title="Engagify's Image Action Detection",description="[Author: Ibrahim Hasani] This Method uses CLIP-VIT [Version: BASE-PATCH-16] to determine if an action is being performed in an image or not. (Binary Classifier). It contrasts an Action against multiple negative labels. Ensure the prompts accurately describe the desired
app.py+12-13