zhiqiulin commited on
Commit
99fb211
·
verified ·
1 Parent(s): 921363c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -11,25 +11,26 @@ print(list_all_vqascore_models())
11
  # Initialize the model only once
12
  model_pipe = None
13
 
 
14
  def initialize_model(model_name):
15
- print("Initializing model...")
16
  global model_pipe
17
  if model_pipe is None:
18
  model_pipe = VQAScore(model=model_name) # our recommended scoring model
19
- print("Model initialized!")
20
  return model_pipe
21
 
22
  @spaces.GPU
23
- def generate(image, text):
 
24
  print("Image:", image)
25
  print("Text:", text)
26
- model_pipe = initialize_model("clip-flant5-xl")
27
  return model_pipe(images=[image], texts=[text])
28
 
29
  iface = gr.Interface(
30
  fn=generate, # function to call
31
- # 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
32
- inputs=[gr.Image(type="filepath"), gr.Textbox(label="Prompt")], # define the types of inputs
33
  outputs="number", # define the type of output
34
  title="VQAScore", # title of the app
35
  description="This model evaluates the similarity between an image and a text prompt."
 
11
  # Initialize the model only once
12
  model_pipe = None
13
 
14
+ @spaces.GPU
15
  def initialize_model(model_name):
 
16
  global model_pipe
17
  if model_pipe is None:
18
  model_pipe = VQAScore(model=model_name) # our recommended scoring model
19
+ print("Model initialized!")
20
  return model_pipe
21
 
22
  @spaces.GPU
23
+ def generate(model_name, image, text):
24
+ print("Model_name:", model_name)
25
  print("Image:", image)
26
  print("Text:", text)
27
+ model_pipe = initialize_model(model_name)
28
  return model_pipe(images=[image], texts=[text])
29
 
30
  iface = gr.Interface(
31
  fn=generate, # function to call
32
+ 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
33
+ # inputs=[gr.Image(type="filepath"), gr.Textbox(label="Prompt")], # define the types of inputs
34
  outputs="number", # define the type of output
35
  title="VQAScore", # title of the app
36
  description="This model evaluates the similarity between an image and a text prompt."