NourFakih commited on
Commit
034827d
·
verified ·
1 Parent(s): 3eb8038

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -9,9 +9,9 @@ from PIL import Image
9
  device = 'cpu'
10
 
11
  # Load the pretrained model, feature extractor, and tokenizer
12
- model = VisionEncoderDecoderModel.from_pretrained("NourFakih/Vit-GPT2-COCO2017Flickr-01").to(device)
13
- feature_extractor = ViTImageProcessor.from_pretrained("NourFakih/Vit-GPT2-COCO2017Flickr-01")
14
- tokenizer = AutoTokenizer.from_pretrained("NourFakih/Vit-GPT2-COCO2017Flickr-01")
15
 
16
  def predict(image, max_length=64, num_beams=4):
17
  # Process the input image
@@ -36,7 +36,7 @@ def process_images(image_files):
36
  except Exception as e:
37
  print(f"Skipping file {image_file}: {e}")
38
 
39
- return captions
40
 
41
  def process_zip_files(zip_file_paths):
42
  # Create a directory to extract images
@@ -60,7 +60,7 @@ def process_zip_files(zip_file_paths):
60
  except Exception as e:
61
  print(f"Skipping file {file}: {e}")
62
 
63
- return captions
64
 
65
  def save_captions_to_csv(captions, csv_file_path='image_captions.csv'):
66
  with open(csv_file_path, mode='w', newline='') as file:
 
9
  device = 'cpu'
10
 
11
  # Load the pretrained model, feature extractor, and tokenizer
12
+ model = VisionEncoderDecoderModel.from_pretrained("NourFakih/Vit-GPT2-COCO2017Flickr-02").to(device)
13
+ feature_extractor = ViTImageProcessor.from_pretrained("NourFakih/Vit-GPT2-COCO2017Flickr-02")
14
+ tokenizer = AutoTokenizer.from_pretrained("NourFakih/Vit-GPT2-COCO2017Flickr-02")
15
 
16
  def predict(image, max_length=64, num_beams=4):
17
  # Process the input image
 
36
  except Exception as e:
37
  print(f"Skipping file {image_file}: {e}")
38
 
39
+ return csv_file_path = save_captions_to_csv(captions, csv_file_path='image_captions.csv')
40
 
41
  def process_zip_files(zip_file_paths):
42
  # Create a directory to extract images
 
60
  except Exception as e:
61
  print(f"Skipping file {file}: {e}")
62
 
63
+ return csv_file_path = save_captions_to_csv(captions, csv_file_path='zip_captions.csv')
64
 
65
  def save_captions_to_csv(captions, csv_file_path='image_captions.csv'):
66
  with open(csv_file_path, mode='w', newline='') as file: