Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from transformers import
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
-
# Load model and
|
| 7 |
-
model_id = "dalle-mini/dalle-
|
| 8 |
-
model =
|
| 9 |
-
|
| 10 |
|
| 11 |
# Function to generate image
|
| 12 |
def generate_image(prompt, num_inference_steps=50):
|
| 13 |
-
inputs =
|
| 14 |
|
| 15 |
# Generate images
|
| 16 |
with torch.no_grad():
|
| 17 |
-
outputs = model.generate(**inputs,
|
| 18 |
|
| 19 |
-
# Convert to PIL image
|
| 20 |
-
image =
|
| 21 |
-
image = Image.open(io.BytesIO(image))
|
| 22 |
|
| 23 |
return image
|
| 24 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from transformers import DalleBartTokenizer, DalleBartForConditionalGeneration
|
| 4 |
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
|
| 7 |
+
# Load model and tokenizer
|
| 8 |
+
model_id = "dalle-mini/dalle-mini" # Example model id; adjust if needed
|
| 9 |
+
model = DalleBartForConditionalGeneration.from_pretrained(model_id)
|
| 10 |
+
tokenizer = DalleBartTokenizer.from_pretrained(model_id)
|
| 11 |
|
| 12 |
# Function to generate image
|
| 13 |
def generate_image(prompt, num_inference_steps=50):
|
| 14 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 15 |
|
| 16 |
# Generate images
|
| 17 |
with torch.no_grad():
|
| 18 |
+
outputs = model.generate(**inputs, num_beams=num_inference_steps)
|
| 19 |
|
| 20 |
+
# Convert tensor to PIL image
|
| 21 |
+
image = Image.fromarray(outputs[0].cpu().numpy().astype('uint8'))
|
|
|
|
| 22 |
|
| 23 |
return image
|
| 24 |
|