import gradio as gr from PIL import Image from huggingface_hub import hf_hub_url from torchvision.transforms import ToTensor from torchvision.utils import save_image from transformers import CLIPProcessor, CLIPModel def generate_image(prompt, model_name): model = CLIPModel.from_pretrained(model_name) processor = CLIPProcessor.from_pretrained(model_name) inputs = processor(text=prompt, return_tensors="pt", padding=True, truncation=True) outputs = model.generate(**inputs) save_image(outputs, 'generated_image.png') return 'generated_image.png' iface = gr.Interface( fn=generate_image, inputs=[gr.inputs.Textbox(label="Enter your prompt"), gr.inputs.Dropdown(choices=['openai/clip-vit-base-patch32', 'openai/clip-vit-large-patch32'], label="Select a model")], outputs=gr.outputs.Image(type="pil"), ) iface.launch()