Spaces:
Runtime error
Runtime error
Commit
·
cbf04ef
1
Parent(s):
256abb9
Update app.py
Browse files
app.py
CHANGED
@@ -101,7 +101,7 @@ examples = [
|
|
101 |
"What are the things I should be cautious about when I visit here?",
|
102 |
]
|
103 |
]
|
104 |
-
def
|
105 |
image = image_processor(images=image.convert('RGB'), return_tensors='pt')['pixel_values']
|
106 |
image_features = visual_encoder.encode_images(image.unsqueeze(0))
|
107 |
emb_mixer.set_image_embeddings(image_features)
|
@@ -116,15 +116,15 @@ with gr.Blocks(title=title) as demo:
|
|
116 |
with gr.Column():
|
117 |
image = gr.Image(type='pil', label="Image")
|
118 |
with gr.Column():
|
119 |
-
prompt = gr.Textbox(lines=
|
120 |
value="Assistant: Please upload an image and ask a question.")
|
121 |
-
with gr.Column():
|
122 |
with gr.Row():
|
123 |
submit = gr.Button("Submit", variant="primary")
|
124 |
-
clear = gr.Button("Clear", variant="secondary")
|
|
|
125 |
output = gr.Textbox(label="Output", lines=5)
|
126 |
data = gr.Dataset(components=[image, prompt], samples=examples, label="Examples", headers=["Image", "Prompt"])
|
127 |
-
submit.click(
|
128 |
clear.click(lambda: None, [], [output])
|
129 |
data.click(lambda x: x, [data], [image, prompt])
|
130 |
|
|
|
101 |
"What are the things I should be cautious about when I visit here?",
|
102 |
]
|
103 |
]
|
104 |
+
def chatbot(image, question):
|
105 |
image = image_processor(images=image.convert('RGB'), return_tensors='pt')['pixel_values']
|
106 |
image_features = visual_encoder.encode_images(image.unsqueeze(0))
|
107 |
emb_mixer.set_image_embeddings(image_features)
|
|
|
116 |
with gr.Column():
|
117 |
image = gr.Image(type='pil', label="Image")
|
118 |
with gr.Column():
|
119 |
+
prompt = gr.Textbox(lines=3, label="Prompt",
|
120 |
value="Assistant: Please upload an image and ask a question.")
|
|
|
121 |
with gr.Row():
|
122 |
submit = gr.Button("Submit", variant="primary")
|
123 |
+
clear = gr.Button("Clear", variant="secondary")
|
124 |
+
with gr.Column():
|
125 |
output = gr.Textbox(label="Output", lines=5)
|
126 |
data = gr.Dataset(components=[image, prompt], samples=examples, label="Examples", headers=["Image", "Prompt"])
|
127 |
+
submit.click(chatbot, [image, prompt], [output])
|
128 |
clear.click(lambda: None, [], [output])
|
129 |
data.click(lambda x: x, [data], [image, prompt])
|
130 |
|