Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -63,12 +63,12 @@ def generate_story(image, theme, genre, word_count):
|
|
63 |
|
64 |
|
65 |
# Generate story based on the caption
|
66 |
-
story_prompt = f"Write an interesting {theme} story in the {genre} genre. The story should be within {word_count} words
|
67 |
|
68 |
llm = OpenAI(model_name="gpt-3.5-turbo-instruct", openai_api_key=openai_api_key, max_tokens=1000)
|
69 |
story = llm.invoke(story_prompt)
|
70 |
|
71 |
-
return
|
72 |
except Exception as e:
|
73 |
return f"An error occurred during inference: {str(e)}"
|
74 |
|
@@ -77,15 +77,21 @@ def generate_story(image, theme, genre, word_count):
|
|
77 |
|
78 |
'''
|
79 |
from transformers import pipeline, AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
|
|
80 |
# Load text generation model
|
|
|
81 |
text_generation_model = pipeline("text-generation", model="distilbert/distilgpt2")
|
|
|
82 |
# Load image captioning model
|
|
|
83 |
encoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
84 |
decoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
85 |
model_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
|
|
86 |
feature_extractor = ViTFeatureExtractor.from_pretrained(encoder_checkpoint)
|
87 |
tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
|
88 |
model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
|
|
|
89 |
def generate_story(image, theme, genre, word_count):
|
90 |
try:
|
91 |
# Preprocess the image
|
@@ -103,6 +109,7 @@ def generate_story(image, theme, genre, word_count):
|
|
103 |
story = text_generation_model(story_prompt, max_length=150)[0]["generated_text"]
|
104 |
|
105 |
return caption_text, story
|
|
|
106 |
except Exception as e:
|
107 |
return f"An error occurred during inference: {str(e)}"
|
108 |
'''
|
|
|
63 |
|
64 |
|
65 |
# Generate story based on the caption
|
66 |
+
story_prompt = f"Write an interesting {theme} story in the {genre} genre about {caption_text}. The story should be within {word_count} words."
|
67 |
|
68 |
llm = OpenAI(model_name="gpt-3.5-turbo-instruct", openai_api_key=openai_api_key, max_tokens=1000)
|
69 |
story = llm.invoke(story_prompt)
|
70 |
|
71 |
+
return caption_text, story
|
72 |
except Exception as e:
|
73 |
return f"An error occurred during inference: {str(e)}"
|
74 |
|
|
|
77 |
|
78 |
'''
|
79 |
from transformers import pipeline, AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
80 |
+
|
81 |
# Load text generation model
|
82 |
+
|
83 |
text_generation_model = pipeline("text-generation", model="distilbert/distilgpt2")
|
84 |
+
|
85 |
# Load image captioning model
|
86 |
+
|
87 |
encoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
88 |
decoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
89 |
model_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
90 |
+
|
91 |
feature_extractor = ViTFeatureExtractor.from_pretrained(encoder_checkpoint)
|
92 |
tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
|
93 |
model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
|
94 |
+
|
95 |
def generate_story(image, theme, genre, word_count):
|
96 |
try:
|
97 |
# Preprocess the image
|
|
|
109 |
story = text_generation_model(story_prompt, max_length=150)[0]["generated_text"]
|
110 |
|
111 |
return caption_text, story
|
112 |
+
|
113 |
except Exception as e:
|
114 |
return f"An error occurred during inference: {str(e)}"
|
115 |
'''
|