Spaces:
Running
Running
import gradio as gr | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
# Moondream does not support the HuggingFace pipeline system, so we have to do it manually | |
moondream_id = "vikhyatk/moondream2" | |
moondream_revision = "2024-04-02" | |
moondream_tokenizer = AutoTokenizer.from_pretrained(moondream_id, code_revision=moondream_revision) | |
moondream_model = AutoModelForCausalLM.from_pretrained( | |
moondream_id, trust_remote_code=True, code_revision=moondream_revision | |
) | |
with gr.Blocks() as app: | |
gr.Markdown( | |
""" | |
# Food Identifier | |
Final project for IAT 481 at Simon Fraser University, Spring 2024. | |
""" | |
) | |
with gr.Row(): | |
prompt = gr.Textbox(label="Input", value="Describe this image.") | |
submit = gr.Button("Submit") | |
with gr.Row(): | |
img = gr.Image(label="Image") | |
output = gr.TextArea(label="Output") | |
submit.click(moondream_model.answer_question, [img, prompt, moondream_tokenizer], output) | |
prompt.submit(moondream_model.answer_question, [img, prompt, moondream_tokenizer], output) | |
if __name__ == "__main__": | |
app.launch() | |