Dendup commited on
Commit
7d9e246
1 Parent(s): 6195349

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
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
- 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(input_ids, max_length=200, num_return_sequences=1, pad_token_id=tokenizer_gpt2.eos_token_id)
39
-
40
- # Decode and display the story
41
- story_text = tokenizer_gpt2.decode(story[0], skip_special_tokens=True)
42
- st.text_area("Generated Story", story_text, height=250)
 
 
 
 
 
 
 
 
 
 
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)