Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
-
import torch
|
4 |
from PIL import Image
|
5 |
|
6 |
-
# Load
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
10 |
def generate_image(text):
|
11 |
# Tokenize input text
|
12 |
input_ids = tokenizer.encode(text, return_tensors="pt")
|
@@ -24,13 +35,13 @@ def generate_image(text):
|
|
24 |
|
25 |
# Create Gradio interface
|
26 |
iface = gr.Interface(
|
27 |
-
fn=generate_image,
|
28 |
-
inputs=
|
29 |
-
outputs="image",
|
30 |
-
title="
|
31 |
-
description="
|
32 |
theme="huggingface"
|
33 |
)
|
34 |
|
35 |
-
# Launch
|
36 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
3 |
from PIL import Image
|
4 |
|
5 |
+
# Load the pipeline for text generation
|
6 |
+
text_generator = pipeline(
|
7 |
+
"text-generation",
|
8 |
+
model="Ar4ikov/gpt2-650k-stable-diffusion-prompt-generator",
|
9 |
+
tokenizer="gpt2"
|
10 |
+
)
|
11 |
+
|
12 |
+
# Load tokenizer and model for image generation
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("stablediffusionapi/juggernaut-xl-v8")
|
14 |
+
model = AutoModelForCausalLM.from_pretrained("stablediffusionapi/juggernaut-xl-v8")
|
15 |
+
|
16 |
+
# Function to generate text based on input prompt
|
17 |
+
def generate_text(prompt):
|
18 |
+
return text_generator(prompt, max_length=77)[0]["generated_text"]
|
19 |
|
20 |
+
# Function to generate image based on input text
|
21 |
def generate_image(text):
|
22 |
# Tokenize input text
|
23 |
input_ids = tokenizer.encode(text, return_tensors="pt")
|
|
|
35 |
|
36 |
# Create Gradio interface
|
37 |
iface = gr.Interface(
|
38 |
+
fn=[generate_text, generate_image],
|
39 |
+
inputs=["textbox", "textbox"],
|
40 |
+
outputs=["textbox", "image"],
|
41 |
+
title="AI Art Prompt Generator",
|
42 |
+
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.",
|
43 |
theme="huggingface"
|
44 |
)
|
45 |
|
46 |
+
# Launch the interface
|
47 |
+
iface.launch()
|