Spaces:
Runtime error
Runtime error
Commit
•
ecc5d7e
1
Parent(s):
33ba4b4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
GIT_TOKEN = os.environ.get("GIT_TOKEN")
|
5 |
+
|
6 |
+
lib_url = f"git+https://vasudevgupta7:{GIT_TOKEN}@github.com/vasudevgupta7/huggingface-task@main"
|
7 |
+
subprocess.run(f"pip3 install -q {lib_url}".split())
|
8 |
+
|
9 |
+
import torch
|
10 |
+
import gradio as gr
|
11 |
+
from pytorch_pretrained_biggan import BigGAN
|
12 |
+
from transformers import AutoModel, AutoTokenizer
|
13 |
+
from huggingface_task.autoencoder import AutoEncoder
|
14 |
+
from huggingface_task.run_model import generate_image_from_text
|
15 |
+
|
16 |
+
biggan_id = 'biggan-deep-128'
|
17 |
+
text_encoder_id = "distilbert-base-uncased"
|
18 |
+
autoencoder_id = "vasudevgupta/biggan-mapping-model"
|
19 |
+
|
20 |
+
text_tokenizer = AutoTokenizer.from_pretrained(text_encoder_id)
|
21 |
+
text_model = AutoModel.from_pretrained(text_encoder_id)
|
22 |
+
|
23 |
+
autoencoder = AutoEncoder.from_pretrained(autoencoder_id)
|
24 |
+
biggan = BigGAN.from_pretrained(biggan_id)
|
25 |
+
|
26 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
27 |
+
biggan.to(device).eval()
|
28 |
+
text_model.to(device).eval()
|
29 |
+
autoencoder.to(device).eval()
|
30 |
+
|
31 |
+
def get_image(text_query):
|
32 |
+
return generate_image_from_text(text_query, text_tokenizer, text_model, autoencoder, biggan, device=device)
|
33 |
+
|
34 |
+
gr.Interface(fn=get_image, inputs="text", outputs="image").launch()
|