zhiqiulin commited on
Commit
171793b
·
verified ·
1 Parent(s): 37efe85

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+
4
+ from t2v_metrics import VQAScore, list_all_vqascore_models
5
+
6
+ print(list_all_vqascore_models())
7
+
8
+ # Initialize the model only once
9
+ model_pipe = None
10
+
11
+ def initialize_model(model_name):
12
+ print("Initializing model...")
13
+ global model_pipe
14
+ if model_pipe is None:
15
+ model_pipe = VQAScore(model=model_name) # our recommended scoring model
16
+ print("Model initialized!")
17
+ return model_pipe
18
+
19
+ @spaces.GPU
20
+ def generate(model_name, image, text):
21
+ pipe = initialize_model(model_name)
22
+ return pipe(image, text)
23
+
24
+ iface = gr.Interface(
25
+ fn=generate, # function to call
26
+ inputs=[gr.Dropdown(["clip-flant5-xl", "clip-flant5-xxl"], label="Model Name"), gr.Image(type="pil"), gr.Textbox(label="Prompt")], # define the types of inputs
27
+ outputs="number", # define the type of output
28
+ title="VQAScore", # title of the app
29
+ description="This model evaluates the similarity between an image and a text prompt."
30
+ ).launch()