Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
3 |
from PIL import Image
|
4 |
|
|
|
|
|
|
|
5 |
# Load image captioning model
|
6 |
encoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
7 |
decoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
@@ -11,6 +15,8 @@ feature_extractor = ViTFeatureExtractor.from_pretrained(encoder_checkpoint)
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
|
12 |
model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint)
|
13 |
|
|
|
|
|
14 |
def generate_story(image, genre, style):
|
15 |
try:
|
16 |
# Preprocess the image
|
@@ -32,16 +38,18 @@ def generate_story(image, genre, style):
|
|
32 |
return f"An error occurred during inference: {str(e)}"
|
33 |
|
34 |
|
|
|
35 |
# Gradio interface
|
36 |
input_image = gr.Image(label="Select Image",type="pil")
|
37 |
input_genre = gr.Dropdown(["Hindi", "Spanish", "Portuguese", "French", "German", "Italian", "Russian", "Japanese"], label="Input Genre")
|
38 |
input_style = gr.Dropdown(["Hindi", "Spanish", "Portuguese", "French", "German", "Italian", "Russian", "Japanese"], label="Input Style")
|
39 |
output_text = gr.Textbox(label="Generated Story",lines=8)
|
40 |
|
|
|
41 |
gr.Interface(
|
42 |
fn=generate_story,
|
43 |
inputs=[input_image, input_genre, input_style],
|
44 |
outputs=output_text,
|
45 |
title="Image to Story Generator",
|
46 |
-
description="Generate a story from an image taking genre and style as input."
|
47 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
|
4 |
from PIL import Image
|
5 |
|
6 |
+
# Load text generation model
|
7 |
+
text_generation_model = pipeline(task="text-generation")
|
8 |
+
|
9 |
# Load image captioning model
|
10 |
encoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
11 |
decoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
|
|
|
15 |
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
|
|
|
38 |
return f"An error occurred during inference: {str(e)}"
|
39 |
|
40 |
|
41 |
+
|
42 |
# Gradio interface
|
43 |
input_image = gr.Image(label="Select Image",type="pil")
|
44 |
input_genre = gr.Dropdown(["Hindi", "Spanish", "Portuguese", "French", "German", "Italian", "Russian", "Japanese"], label="Input Genre")
|
45 |
input_style = gr.Dropdown(["Hindi", "Spanish", "Portuguese", "French", "German", "Italian", "Russian", "Japanese"], label="Input Style")
|
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.",
|
55 |
+
).launch()
|