File size: 1,065 Bytes
74a9c90
f8fcf48
74a9c90
f8fcf48
6d2b5eb
 
f8fcf48
 
 
74a9c90
6d2b5eb
74a9c90
 
f8fcf48
 
 
 
 
 
 
 
74a9c90
90483a6
2657836
90483a6
2657836
 
 
90483a6
f8fcf48
74a9c90
 
 
6d2b5eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
from brain import StoryGenerator

story_generator = StoryGenerator()


def generate_story_from_image(image, model_name):
    """Wrapper function to use with Gradio interface"""
    return story_generator.generate_story_from_image(image, model_name)


iface = gr.Interface(
    fn=generate_story_from_image,
    inputs=[
        gr.Image(type="pil"),
        gr.Dropdown(
            choices=list(story_generator.text_models.keys()),
            label="Choose a model",
            value="Mistral-7B"
        )
    ],
    outputs="text",
    title="Bedtime Stories Generator",
    description="""This space uses image captioning and language models to generate
    stories. Upload an image, choose a model, and get a children's story based on it!
    Images are first converted to text using a pre-trained image captioning model,
    and then the text is used as part of a calibrated prompt for a language model to
    generate a story.
    """,
    examples=[["assets/image.jpg", "Mistral-7B"]],
)

if __name__ == "__main__":
    iface.launch()