EVad commited on
Commit
d202e0a
·
1 Parent(s): 3c3c4fa

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -6,6 +6,8 @@ import gradio as gr
6
 
7
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
8
  from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
 
 
9
 
10
  model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
11
  feature_extractor = ViTFeatureExtractor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
@@ -31,6 +33,7 @@ gen_kwargs = {"max_length": max_length, "num_beams": num_beams}
31
 
32
 
33
  def inference(image_paths):
 
34
 
35
  #for image_path in image_paths:
36
  i_image = Image.fromarray(image_paths)
@@ -44,11 +47,16 @@ def inference(image_paths):
44
 
45
  preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
46
  preds = [pred.strip() for pred in preds]
47
-
 
48
 
49
  sample = TTSHubInterface.get_model_input(task, preds)
 
 
50
 
51
  wav, rate = TTSHubInterface.get_prediction(task, model1, generator, sample)
 
 
52
  return wav
53
 
54
 
 
6
 
7
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
8
  from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
9
+ from fairseq.utils import move_to_cuda
10
+
11
 
12
  model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
13
  feature_extractor = ViTFeatureExtractor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
 
33
 
34
 
35
  def inference(image_paths):
36
+ images = []
37
 
38
  #for image_path in image_paths:
39
  i_image = Image.fromarray(image_paths)
 
47
 
48
  preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True)
49
  preds = [pred.strip() for pred in preds]
50
+ preds = ' '.join(str(e) for e in preds)
51
+ #print(preds)
52
 
53
  sample = TTSHubInterface.get_model_input(task, preds)
54
+ sample = move_to_cuda(sample)
55
+
56
 
57
  wav, rate = TTSHubInterface.get_prediction(task, model1, generator, sample)
58
+ wav = wav.to("cpu")
59
+
60
  return wav
61
 
62