File size: 787 Bytes
29e745d
ccf2912
 
 
29e745d
ccf2912
 
 
29e745d
ccf2912
 
 
29e745d
ccf2912
29e745d
ccf2912
 
 
 
 
 
c4392b4
29e745d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from PIL import Image
from huggingface_hub import hf_hub_url
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()