Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "False"
|
|
| 3 |
os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
| 4 |
import numpy as np
|
| 5 |
import gradio as gr
|
| 6 |
-
import spaces
|
| 7 |
import torch
|
| 8 |
import torch.nn.functional as F
|
| 9 |
from PIL import Image
|
|
@@ -34,7 +34,7 @@ model.eval()
|
|
| 34 |
mask_token_id = model.config.mask_token_id
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
def text_to_image_generation(input_text, guidance_scale=1.75, generation_timesteps=18):
|
| 39 |
prompts = [input_text]
|
| 40 |
config.training.batch_size = config.batch_size = 1
|
|
@@ -92,7 +92,7 @@ def text_to_image_generation(input_text, guidance_scale=1.75, generation_timeste
|
|
| 92 |
return images[0]
|
| 93 |
|
| 94 |
|
| 95 |
-
|
| 96 |
def text_guided_inpainting(input_text, inpainting_image, inpainting_mask_input, guidance_scale=1.75, generation_timesteps=16):
|
| 97 |
# pre-process inpainting mask
|
| 98 |
alpha_channel = inpainting_mask_input["layers"][0][:, :, 3]
|
|
@@ -176,7 +176,7 @@ def text_guided_inpainting(input_text, inpainting_image, inpainting_mask_input,
|
|
| 176 |
return images[0]
|
| 177 |
|
| 178 |
|
| 179 |
-
|
| 180 |
def text_guided_extrapolation(input_img, input_text, left_ext, right_ext, guidance_scale=1.75, generation_timesteps=16):
|
| 181 |
config.offset = 0
|
| 182 |
config.training.batch_size = config.batch_size = 1
|
|
@@ -301,7 +301,7 @@ def text_guided_extrapolation(input_img, input_text, left_ext, right_ext, guidan
|
|
| 301 |
return images[0]
|
| 302 |
|
| 303 |
|
| 304 |
-
|
| 305 |
def multimodal_understanding(input_img, input_text, chat_history):
|
| 306 |
top_k = 1 # retain only the top_k most likely tokens, clamp others to have 0 probability
|
| 307 |
|
|
@@ -549,4 +549,4 @@ with gr.Blocks() as demo:
|
|
| 549 |
clear = gr.ClearButton([msg, chatbot])
|
| 550 |
msg.submit(multimodal_understanding, [chat_input_img, msg, chatbot], [msg, chatbot])
|
| 551 |
|
| 552 |
-
demo.launch()
|
|
|
|
| 3 |
os.environ["TOKENIZERS_PARALLELISM"] = "true"
|
| 4 |
import numpy as np
|
| 5 |
import gradio as gr
|
| 6 |
+
#import spaces
|
| 7 |
import torch
|
| 8 |
import torch.nn.functional as F
|
| 9 |
from PIL import Image
|
|
|
|
| 34 |
mask_token_id = model.config.mask_token_id
|
| 35 |
|
| 36 |
|
| 37 |
+
#@spaces.GPU
|
| 38 |
def text_to_image_generation(input_text, guidance_scale=1.75, generation_timesteps=18):
|
| 39 |
prompts = [input_text]
|
| 40 |
config.training.batch_size = config.batch_size = 1
|
|
|
|
| 92 |
return images[0]
|
| 93 |
|
| 94 |
|
| 95 |
+
#@spaces.GPU
|
| 96 |
def text_guided_inpainting(input_text, inpainting_image, inpainting_mask_input, guidance_scale=1.75, generation_timesteps=16):
|
| 97 |
# pre-process inpainting mask
|
| 98 |
alpha_channel = inpainting_mask_input["layers"][0][:, :, 3]
|
|
|
|
| 176 |
return images[0]
|
| 177 |
|
| 178 |
|
| 179 |
+
#@spaces.GPU
|
| 180 |
def text_guided_extrapolation(input_img, input_text, left_ext, right_ext, guidance_scale=1.75, generation_timesteps=16):
|
| 181 |
config.offset = 0
|
| 182 |
config.training.batch_size = config.batch_size = 1
|
|
|
|
| 301 |
return images[0]
|
| 302 |
|
| 303 |
|
| 304 |
+
#@spaces.GPU
|
| 305 |
def multimodal_understanding(input_img, input_text, chat_history):
|
| 306 |
top_k = 1 # retain only the top_k most likely tokens, clamp others to have 0 probability
|
| 307 |
|
|
|
|
| 549 |
clear = gr.ClearButton([msg, chatbot])
|
| 550 |
msg.submit(multimodal_understanding, [chat_input_img, msg, chatbot], [msg, chatbot])
|
| 551 |
|
| 552 |
+
demo.launch(share = True)
|