Spaces:
Running
Running
Try loading moondream2 using parts of their example
Browse files
app.py
CHANGED
@@ -1,18 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
|
4 |
-
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
-
|
6 |
-
# from PIL import Image
|
7 |
-
|
8 |
|
|
|
9 |
moondream_id = "vikhyatk/moondream2"
|
10 |
moondream_revision = "2024-04-02"
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
pipe = pipeline(model=moondream_id, revision=moondream_revision, trust_remote_code=True)
|
16 |
|
17 |
with gr.Blocks() as app:
|
18 |
gr.Markdown(
|
@@ -26,7 +21,11 @@ with gr.Blocks() as app:
|
|
26 |
prompt = gr.Textbox(label="Input", value="Describe this image.")
|
27 |
submit = gr.Button(label="Submit")
|
28 |
with gr.Row():
|
29 |
-
img = gr.Image(
|
|
|
|
|
|
|
|
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Moondream does not support the HuggingFace pipeline system, so we have to do it manually
|
5 |
moondream_id = "vikhyatk/moondream2"
|
6 |
moondream_revision = "2024-04-02"
|
7 |
+
moondream_tokenizer = AutoTokenizer.from_pretrained(moondream_id, code_revision=moondream_revision)
|
8 |
+
moondream_model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
moondream_id, trust_remote_code=True, code_revision=moondream_revision
|
10 |
+
)
|
|
|
11 |
|
12 |
with gr.Blocks() as app:
|
13 |
gr.Markdown(
|
|
|
21 |
prompt = gr.Textbox(label="Input", value="Describe this image.")
|
22 |
submit = gr.Button(label="Submit")
|
23 |
with gr.Row():
|
24 |
+
img = gr.Image(label="Image")
|
25 |
+
output = gr.TextArea(label="Output")
|
26 |
+
|
27 |
+
submit.click(moondream_model.answer_question, [img, prompt, moondream_tokenizer], output)
|
28 |
+
prompt.submit(moondream_model.answer_question, [img, prompt, moondream_tokenizer], output)
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
app.launch()
|