Spaces:
Runtime error
Runtime error
File size: 1,539 Bytes
a415ec3 c8e431d a415ec3 c8e431d a415ec3 0348566 a415ec3 c8e431d 0348566 a415ec3 c8e431d a415ec3 c8e431d a415ec3 da6626c a415ec3 0348566 a415ec3 |
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 |
import gradio as gr
import torch
from transformers import AutoModelForSequenceToSequence, AutoTokenizer
from PIL import Image
from torchvision import transforms
# Load the Text-to-Image model
image_model = AutoModelForSequenceToSequence.from_pretrained("artificialguybr/CuteCartoonRedmond-V2")
image_tokenizer = AutoTokenizer.from_pretrained("artificialguybr/CuteCartoonRedmond-V2")
# Load the Text Generation model
text_model = AutoModelForSequenceToSequence.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1")
text_tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x7B-Instruct-v0.1")
# Define a function to generate an image from text
def generate_image(text):
inputs = image_tokenizer(text, return_tensors="pt")
output = image_model.generate(inputs["input_ids"], attention_mask=inputs["attention_mask"])
image = Image.fromarray(output[0].detach().numpy())
return image
# Define a function to generate text from text
def generate_text(text):
inputs = text_tokenizer(text, return_tensors="pt")
output = text_model.generate(inputs["input_ids"], attention_mask=inputs["attention_mask"])
return text_tokenizer.decode(output[0], skip_special_tokens=True)
# Create a Gradio interface
demo = gr.Interface(
fn=lambda text: {"image": generate_image(text), "text": generate_text(text)},
inputs="text",
outputs=["image", "text"],
title="Text-to-Image and Text Generation",
description="Enter a prompt to generate both an image and text!"
)
# Launch the Gradio app
demo.launch() |