Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,15 +28,24 @@ if uploaded_image is not None:
|
|
28 |
|
29 |
# Generate story from caption
|
30 |
if st.button('Generate Story from Caption'):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Generate story from caption
|
30 |
if st.button('Generate Story from Caption'):
|
31 |
+
st.write("Generating story...")
|
32 |
+
story_prompt = f"Based on the image, here's a story: {caption}"
|
33 |
+
|
34 |
+
# Encode prompt text to input ids
|
35 |
+
input_ids = tokenizer_gpt2.encode(story_prompt, return_tensors='pt')
|
36 |
+
|
37 |
+
# Generate text using GPT-2 model
|
38 |
+
story = model_gpt2.generate(
|
39 |
+
input_ids,
|
40 |
+
max_length=200,
|
41 |
+
num_return_sequences=1,
|
42 |
+
no_repeat_ngram_size=2,
|
43 |
+
temperature=0.9,
|
44 |
+
top_k=50,
|
45 |
+
top_p=0.95,
|
46 |
+
pad_token_id=tokenizer_gpt2.eos_token_id
|
47 |
+
)
|
48 |
+
|
49 |
+
# Decode and display the story
|
50 |
+
story_text = tokenizer_gpt2.decode(story[0], skip_special_tokens=True)
|
51 |
+
st.text_area("Generated Story", story_text, height=250)
|