Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,8 +16,7 @@ tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
|
|
16 |
model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
|
17 |
|
18 |
|
19 |
-
|
20 |
-
def generate_story(image, genre, style):
|
21 |
try:
|
22 |
# Preprocess the image
|
23 |
image = image.convert('RGB')
|
@@ -30,7 +29,8 @@ def generate_story(image, genre, style):
|
|
30 |
caption_text = tokenizer.batch_decode(caption_ids, skip_special_tokens=True)[0]
|
31 |
|
32 |
# Generate story based on the caption
|
33 |
-
story_prompt = f"{
|
|
|
34 |
story = text_generation_model(story_prompt, max_length=150)[0]["generated_text"]
|
35 |
|
36 |
return story
|
@@ -41,14 +41,15 @@ def generate_story(image, genre, style):
|
|
41 |
|
42 |
# Gradio interface
|
43 |
input_image = gr.Image(label="Select Image",type="pil")
|
44 |
-
|
45 |
-
|
|
|
46 |
output_text = gr.Textbox(label="Generated Story",lines=8)
|
47 |
|
48 |
|
49 |
gr.Interface(
|
50 |
fn=generate_story,
|
51 |
-
inputs=[input_image, input_genre, input_style],
|
52 |
outputs=output_text,
|
53 |
title="Image to Story Generator",
|
54 |
description="Generate a story from an image taking genre and style as input.",
|
|
|
16 |
model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
|
17 |
|
18 |
|
19 |
+
def generate_story(image, theme, genre, style):
|
|
|
20 |
try:
|
21 |
# Preprocess the image
|
22 |
image = image.convert('RGB')
|
|
|
29 |
caption_text = tokenizer.batch_decode(caption_ids, skip_special_tokens=True)[0]
|
30 |
|
31 |
# Generate story based on the caption
|
32 |
+
story_prompt = f"Write an interesting {theme} story in the {genre} genre, written in {style} style. The story should be about {caption_text}."
|
33 |
+
|
34 |
story = text_generation_model(story_prompt, max_length=150)[0]["generated_text"]
|
35 |
|
36 |
return story
|
|
|
41 |
|
42 |
# Gradio interface
|
43 |
input_image = gr.Image(label="Select Image",type="pil")
|
44 |
+
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")
|
45 |
+
input_genre = gr.Dropdown(["Fantasy", "Science Fiction", "Mystery/Thriller", "Romance", "Historical Fiction", "Horror", "Adventure", "Drama", "Comedy"], label="Input Genre")
|
46 |
+
input_style = gr.Dropdown(["Classic Literature", "Contemporary Fiction", "Poetic/Prose", "Experimental", "Dialogue-driven", "Descriptive", "Epistolary", "Minimalist", "Surreal/Fantastical"], label="Input Style")
|
47 |
output_text = gr.Textbox(label="Generated Story",lines=8)
|
48 |
|
49 |
|
50 |
gr.Interface(
|
51 |
fn=generate_story,
|
52 |
+
inputs=[input_image, input_theme, input_genre, input_style],
|
53 |
outputs=output_text,
|
54 |
title="Image to Story Generator",
|
55 |
description="Generate a story from an image taking genre and style as input.",
|