File size: 958 Bytes
685ecb2
a897083
685ecb2
 
 
 
 
 
 
 
 
 
 
 
332a6dc
 
685ecb2
a897083
332a6dc
685ecb2
 
 
 
 
 
332a6dc
 
685ecb2
332a6dc
685ecb2
332a6dc
685ecb2
 
586f617
685ecb2
 
332a6dc
 
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
36
37
38
39
import gradio as gr
import spaces
import os

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
os.environ["USER"] = "imagecraft"


import gradio as gr
from src.model.modules.imagecraft import ImageCraft

model = ImageCraft.from_pretrained("nsandiman/imagecraft-ft-co-224")

default_image = "media/images/3.jpg"


@spaces.GPU
def generate(image_path):
    """Process image inputs and generate audio response."""
    transcript, audio_buffer = model.generate(image_path, output_type="buffer")

    return audio_buffer, transcript


imagecraft_app = gr.Interface(
    fn=generate,
    inputs=[
        gr.Image(type="filepath", label="Upload an image", value=default_image),
    ],
    outputs=[gr.Audio(label="Speech"), gr.Textbox(label="Text")],
    title="ImageCraft",
    description="Upload an image and get the speech responses.",
    allow_flagging="never",
)

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