File size: 1,741 Bytes
1312050
d726ff6
62fd8d0
82f7a21
d726ff6
 
 
 
 
 
 
 
 
 
 
 
 
 
82f7a21
d726ff6
62fd8d0
 
 
82f7a21
62fd8d0
 
82f7a21
62fd8d0
 
82f7a21
62fd8d0
 
82f7a21
62fd8d0
82f7a21
62fd8d0
 
d726ff6
 
 
 
 
62fd8d0
 
1312050
d726ff6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
from PIL import Image

# Load the pipeline for text generation
text_generator = pipeline(
    "text-generation",
    model="Ar4ikov/gpt2-650k-stable-diffusion-prompt-generator",
    tokenizer="gpt2"
)

# Load tokenizer and model for image generation
tokenizer = AutoTokenizer.from_pretrained("stablediffusionapi/juggernaut-xl-v8")
model = AutoModelForCausalLM.from_pretrained("stablediffusionapi/juggernaut-xl-v8")

# Function to generate text based on input prompt
def generate_text(prompt):
    return text_generator(prompt, max_length=77)[0]["generated_text"]

# Function to generate image based on input text
def generate_image(text):
    # Tokenize input text
    input_ids = tokenizer.encode(text, return_tensors="pt")

    # Generate image conditioned on input text
    output = model.generate(input_ids, do_sample=True, max_length=128, num_return_sequences=1)

    # Decode generated image tokens to get image
    image_bytes = tokenizer.decode(output[0], skip_special_tokens=True)

    # Convert image bytes to PIL image
    image = Image.open(image_bytes)

    return image

# Create Gradio interface
iface = gr.Interface(
    fn=[generate_text, generate_image],
    inputs=["textbox", "textbox"],
    outputs=["textbox", "image"],
    title="AI Art Prompt Generator",
    description="Art Prompt Generator is a user-friendly interface designed to optimize input for AI Art Generator or Creator. For faster generation speeds, it's recommended to load the model locally with GPUs, as the online demo at Hugging Face Spaces utilizes CPU, resulting in slower processing times.",
    theme="huggingface"
)

# Launch the interface
iface.launch()