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()