Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
import spaces | |
# Initialize the model only once, outside of any function | |
# Ensure that CUDA initialization happens within the worker process | |
model_pipe = None | |
def generate(model_name, image, text): | |
global model_pipe | |
import torch | |
torch.jit.script = lambda f: f | |
from t2v_metrics import VQAScore, list_all_vqascore_models | |
if model_pipe is None: | |
print("Initializing model...") | |
model_pipe = VQAScore(model="clip-flant5-xl", device="cuda") # our recommended scoring model | |
# model_pipe.to("cuda") | |
print(list_all_vqascore_models()) | |
print("Image:", image) | |
print("Text:", text) | |
print("Generating!") | |
result = model_pipe(images=[image], texts=[text]) | |
return result | |
iface = gr.Interface( | |
fn=generate, # function to call | |
inputs=[gr.Dropdown(["clip-flant5-xl", "clip-flant5-xxl"], label="Model Name"), gr.Image(type="filepath"), gr.Textbox(label="Prompt")], # define the types of inputs | |
outputs="number", # define the type of output | |
title="VQAScore", # title of the app | |
description="This model evaluates the similarity between an image and a text prompt." | |
).launch() | |