File size: 1,254 Bytes
f6c9e50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c91d53
f6c9e50
 
 
 
 
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
import gradio as gr
from classification import classify_image
from smolVLMchat import process_chat
from PIL import Image

def classify_func(image: Image.Image):
    """Wrapper for classify_image."""
    return classify_image(image)

def chat_func(text: str, image: Image.Image = None):
    """Wrapper for process_chat."""
    return process_chat(text=text, image=image)

# Gradio app
with gr.Blocks() as demo:
    gr.Markdown("#SmolVLM App: Painting Classifier & Visual Chatbot")

    with gr.Tab("Painting Classification"):
        img_input = gr.Image(type="pil", label="Upload a Painting")
        classify_btn = gr.Button("Classify Image")
        classify_output = gr.JSON(label="Classification Result")
        classify_btn.click(fn=classify_func, inputs=[img_input], outputs=[classify_output])

    with gr.Tab("Visual Chat with SmolVLM"):
        text_input = gr.Textbox(label="Your Text", lines=2, placeholder="Ask something about the image or anything else...")
        img_input2 = gr.Image(type="pil", label="Image for Context")
        chat_btn = gr.Button("Chat")
        chat_output = gr.Textbox(label="Chatbot Response", lines=4)
        chat_btn.click(fn=chat_func, inputs=[text_input, img_input2], outputs=[chat_output])

demo.launch()