Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,23 @@
|
|
| 1 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
-
import torch
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
-
# Load the
|
| 6 |
-
|
| 7 |
-
model = AutoModelForCausalLM.from_pretrained("dalle-mini/dalle-mega")
|
| 8 |
|
| 9 |
-
# Define the function
|
| 10 |
-
def generate_image(
|
| 11 |
-
inputs = tokenizer(
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
outputs = model.generate(**inputs)
|
| 16 |
-
|
| 17 |
-
# Convert output to a format suitable for Gradio
|
| 18 |
-
# This part may need to be adapted based on actual output format
|
| 19 |
-
return outputs
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
fn=generate_image,
|
| 24 |
-
inputs=
|
| 25 |
-
outputs=
|
| 26 |
-
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# Launch the app
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import eBart
|
| 3 |
|
| 4 |
+
# Load the DALL-E Mega model
|
| 5 |
+
model = eBart.from_pretrained("dalle-mini/dalle-mega")
|
|
|
|
| 6 |
|
| 7 |
+
# Define the function to generate images
|
| 8 |
+
def generate_image(text):
|
| 9 |
+
inputs = model.tokenizer(text, return_tensors="pt")
|
| 10 |
+
outputs = model.generate(**inputs)
|
| 11 |
+
image_url = model.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
+
return image_url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Create the Gradio interface
|
| 15 |
+
ui = gr.Interface(
|
| 16 |
fn=generate_image,
|
| 17 |
+
inputs="text",
|
| 18 |
+
outputs="image",
|
| 19 |
+
title="DALL-E Mega Image Generator"
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# Launch the Gradio app
|
| 23 |
+
ui.launch()
|