kusumakar commited on
Commit
82a0b71
1 Parent(s): 6d700e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -10,8 +10,8 @@ tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning"
10
 
11
  # Load the pre-trained model and tokenizer
12
  model_name = "gpt2"
13
- tokenizer = GPT2Tokenizer.from_pretrained(model_name)
14
- model = GPT2LMHeadModel.from_pretrained(model_name)
15
 
16
  def generate_captions(image):
17
  image = Image.open(image).convert("RGB")
@@ -24,13 +24,13 @@ def generate_captions(image):
24
  # Define the Streamlit app
25
  def generate_paragraph(prompt):
26
  # Tokenize the prompt
27
- input_ids = tokenizer.encode(prompt, return_tensors="pt")
28
 
29
  # Generate the paragraph
30
- output = model.generate(input_ids, max_length=200, num_return_sequences=1, early_stopping=True)
31
 
32
  # Decode the generated output into text
33
- paragraph = tokenizer.decode(output[0], skip_special_tokens=True)
34
  return paragraph
35
 
36
  # create the Streamlit app
 
10
 
11
  # Load the pre-trained model and tokenizer
12
  model_name = "gpt2"
13
+ tokenizer_1 = GPT2Tokenizer.from_pretrained(model_name)
14
+ model_2 = GPT2LMHeadModel.from_pretrained(model_name)
15
 
16
  def generate_captions(image):
17
  image = Image.open(image).convert("RGB")
 
24
  # Define the Streamlit app
25
  def generate_paragraph(prompt):
26
  # Tokenize the prompt
27
+ input_ids = tokenizer_1.encode(prompt, return_tensors="pt")
28
 
29
  # Generate the paragraph
30
+ output = model_2.generate(input_ids, max_length=200, num_return_sequences=1, early_stopping=True)
31
 
32
  # Decode the generated output into text
33
+ paragraph = tokenizer_1.decode(output[0], skip_special_tokens=True)
34
  return paragraph
35
 
36
  # create the Streamlit app