|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
from PIL import Image |
|
import gradio as gr |
|
|
|
|
|
model_id = "vikhyatk/moondream2" |
|
revision = "2024-05-20" |
|
model = AutoModelForCausalLM.from_pretrained( |
|
model_id, trust_remote_code=True, revision=revision |
|
) |
|
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision) |
|
|
|
def analyze_image_direct(image, question): |
|
|
|
|
|
return "This is a placeholder answer." |
|
|
|
|
|
custom_css = """ |
|
body { background-color: #800080; } |
|
button { background-color: #9932CC; color: white; } |
|
textarea { background-color: #DDA0DD; color: black; } |
|
""" |
|
|
|
|
|
iface = gr.Interface(fn=analyze_image_direct, |
|
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Enter your question here...")], |
|
outputs='text', |
|
title="Direct Image Question Answering", |
|
description="Upload an image and ask a question about it directly using the model.", |
|
theme="dark", |
|
css=custom_css) |
|
|
|
|
|
iface.launch() |