Irina
smth
6c91d53
raw
history blame contribute delete
1.25 kB
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()