apratim24 commited on
Commit
e66248b
·
verified ·
1 Parent(s): 6af8341

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -21,7 +21,7 @@ tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
21
  model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
22
 
23
 
24
- def generate_story(image, theme, genre):
25
  try:
26
  # Preprocess the image
27
  image = image.convert('RGB')
@@ -34,7 +34,7 @@ def generate_story(image, theme, genre):
34
  caption_text = tokenizer.batch_decode(caption_ids, skip_special_tokens=True)[0]
35
 
36
  # Generate story based on the caption
37
- story_prompt = f"Write an interesting {theme} story in the {genre} genre. The story should be within 100 words about {caption_text}."
38
 
39
  llm = OpenAI(model_name="gpt-3.5-turbo-instruct", openai_api_key=openai_api_key)
40
  story = llm.invoke(story_prompt)
@@ -51,13 +51,14 @@ input_image = gr.Image(label="Select Image",type="pil")
51
  input_theme = gr.Dropdown(["Love and Loss", "Identity and Self-Discovery", "Power and Corruption", "Redemption and Forgiveness", "Survival and Resilience", "Nature and the Environment", "Justice and Injustice", "Friendship and Loyalty", "Hope and Despair"], label="Input Theme")
52
  input_genre = gr.Dropdown(["Fantasy", "Science Fiction", "Poetry", "Mystery/Thriller", "Romance", "Historical Fiction", "Horror", "Adventure", "Drama", "Comedy"], label="Input Genre")
53
  output_caption = gr.Textbox(label="Image Caption", lines=2)
54
- output_text = gr.Textbox(label="Generated Story",lines=8)
55
  examples = [["example1.jpg"], ["example2.jpg"]] # List of example image paths
 
56
 
57
 
58
  gr.Interface(
59
  fn=generate_story,
60
- inputs=[input_image, input_theme, input_genre],
61
  theme='freddyaboulton/dracula_revamped',
62
  outputs=[output_caption, output_text],
63
  examples = examples,
 
21
  model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
22
 
23
 
24
+ def generate_story(image, theme, genre, word_count):
25
  try:
26
  # Preprocess the image
27
  image = image.convert('RGB')
 
34
  caption_text = tokenizer.batch_decode(caption_ids, skip_special_tokens=True)[0]
35
 
36
  # Generate story based on the caption
37
+ story_prompt = f"Write an interesting {theme} story in the {genre} genre. The story should be within {word_count} words about {caption_text}."
38
 
39
  llm = OpenAI(model_name="gpt-3.5-turbo-instruct", openai_api_key=openai_api_key)
40
  story = llm.invoke(story_prompt)
 
51
  input_theme = gr.Dropdown(["Love and Loss", "Identity and Self-Discovery", "Power and Corruption", "Redemption and Forgiveness", "Survival and Resilience", "Nature and the Environment", "Justice and Injustice", "Friendship and Loyalty", "Hope and Despair"], label="Input Theme")
52
  input_genre = gr.Dropdown(["Fantasy", "Science Fiction", "Poetry", "Mystery/Thriller", "Romance", "Historical Fiction", "Horror", "Adventure", "Drama", "Comedy"], label="Input Genre")
53
  output_caption = gr.Textbox(label="Image Caption", lines=2)
54
+ output_text = gr.Textbox(label="Generated Story",lines=10)
55
  examples = [["example1.jpg"], ["example2.jpg"]] # List of example image paths
56
+ word_count_slider = gr.Slider(minimum=50, maximum=200, default=100, label="Word Count")
57
 
58
 
59
  gr.Interface(
60
  fn=generate_story,
61
+ inputs=[input_image, input_theme, input_genre, word_count_slider],
62
  theme='freddyaboulton/dracula_revamped',
63
  outputs=[output_caption, output_text],
64
  examples = examples,