Spaces:
Runtime error
Runtime error
File size: 1,190 Bytes
ecc5d7e c7b5438 ecc5d7e c7b5438 ecc5d7e 957bbf8 ecc5d7e |
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 |
import os
import subprocess
GIT_TOKEN = os.environ.get("GIT_TOKEN")
GIT_USER = "vasudevgupta7"
lib_url = f"git+https://{GIT_USER}:{GIT_TOKEN}@github.com/vasudevgupta7/huggingface-task@main"
subprocess.run(f"pip3 install -q {lib_url}".split())
import torch
import gradio as gr
from transformers import AutoModel, AutoTokenizer
from pytorch_pretrained_biggan import BigGAN
from huggingface_task.autoencoder import AutoEncoder
from huggingface_task.run_model import generate_image_from_text
biggan_id = 'biggan-deep-128'
text_encoder_id = "distilbert-base-uncased"
autoencoder_id = "vasudevgupta/biggan-mapping-model"
text_tokenizer = AutoTokenizer.from_pretrained(text_encoder_id)
text_model = AutoModel.from_pretrained(text_encoder_id)
autoencoder = AutoEncoder.from_pretrained(autoencoder_id)
biggan = BigGAN.from_pretrained(biggan_id)
device = "cuda" if torch.cuda.is_available() else "cpu"
biggan.to(device).eval()
text_model.to(device).eval()
autoencoder.to(device).eval()
def get_image(text_query):
return generate_image_from_text(text_query, text_tokenizer, text_model, autoencoder, biggan, device=device)
gr.Interface(fn=get_image, inputs="text", outputs="image").launch()
|