Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
14 |
-
|
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 =
|
28 |
|
29 |
# Generate the paragraph
|
30 |
-
output =
|
31 |
|
32 |
# Decode the generated output into text
|
33 |
-
paragraph =
|
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
|