Add application file
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
4 |
-
import numpy as np
|
5 |
|
6 |
# Load the model and tokenizer
|
7 |
model_id = "vikhyatk/moondream2"
|
@@ -12,23 +11,25 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
13 |
|
14 |
def analyze_image_direct(image, question):
|
15 |
-
#
|
16 |
-
#
|
17 |
-
|
18 |
-
enc_image = model.encode_image(image) # This method might not exist; adjust based on actual model capabilities
|
19 |
-
|
20 |
-
# Generate an answer to the question based on the encoded image
|
21 |
-
# Note: This step is hypothetical and depends on the model's capabilities
|
22 |
-
answer = model.answer_question(enc_image, question, tokenizer) # Adjust based on actual model capabilities
|
23 |
-
|
24 |
-
return answer
|
25 |
|
26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
iface = gr.Interface(fn=analyze_image_direct,
|
28 |
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Enter your question here...")],
|
29 |
outputs='text',
|
30 |
title="Direct Image Question Answering",
|
31 |
-
description="Upload an image and ask a question about it directly using the model."
|
|
|
|
|
32 |
|
33 |
# Launch the interface
|
34 |
iface.launch()
|
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
# Load the model and tokenizer
|
6 |
model_id = "vikhyatk/moondream2"
|
|
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
|
12 |
|
13 |
def analyze_image_direct(image, question):
|
14 |
+
# This is a placeholder function. You need to implement the logic based on your model's capabilities.
|
15 |
+
# For demonstration, it returns a static response.
|
16 |
+
return "This is a placeholder answer."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Define custom CSS to make the interface purple
|
19 |
+
custom_css = """
|
20 |
+
body { background-color: #800080; }
|
21 |
+
button { background-color: #9932CC; color: white; }
|
22 |
+
textarea { background-color: #DDA0DD; color: black; }
|
23 |
+
"""
|
24 |
+
|
25 |
+
# Create Gradio interface with custom CSS for a purple theme
|
26 |
iface = gr.Interface(fn=analyze_image_direct,
|
27 |
inputs=[gr.Image(type="pil"), gr.Textbox(lines=2, placeholder="Enter your question here...")],
|
28 |
outputs='text',
|
29 |
title="Direct Image Question Answering",
|
30 |
+
description="Upload an image and ask a question about it directly using the model.",
|
31 |
+
theme="dark", # Use the dark theme as a base
|
32 |
+
css=custom_css) # Apply custom CSS
|
33 |
|
34 |
# Launch the interface
|
35 |
iface.launch()
|