Spaces:
Runtime error
Runtime error
Greatmonkey
commited on
Commit
•
ea026b7
1
Parent(s):
7c116d2
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
model_id = "vikhyatk/moondream2"
|
6 |
+
revision = "2024-03-06"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
model_id, trust_remote_code=True, revision=revision
|
9 |
+
)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
11 |
+
|
12 |
+
def describe_image(image):
|
13 |
+
image = Image.fromarray(image)
|
14 |
+
enc_image = model.encode_image(image)
|
15 |
+
description = model.answer_question(enc_image, "Describe this image.", tokenizer)
|
16 |
+
return description
|
17 |
+
|
18 |
+
input_image = gr.inputs.Image()
|
19 |
+
output_text = gr.outputs.Textbox()
|
20 |
+
|
21 |
+
gr.Interface(
|
22 |
+
fn=describe_image,
|
23 |
+
inputs=input_image,
|
24 |
+
outputs=output_text,
|
25 |
+
title="Image Description",
|
26 |
+
description="Enter an image and get its description.",
|
27 |
+
).launch()
|