Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
|
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
@spaces.GPU
|
9 |
-
def
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
gr.Interface(fn=
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
4 |
+
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
5 |
|
6 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
7 |
+
|
8 |
+
prompt_format = f"USER: <image>\n{}\nASSISTANT:"
|
9 |
+
image_file = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
10 |
+
|
11 |
+
model = LlavaForConditionalGeneration.from_pretrained(
|
12 |
+
model_id,
|
13 |
+
torch_dtype=torch.float16,
|
14 |
+
low_cpu_mem_usage=True,
|
15 |
+
).cuda()
|
16 |
+
|
17 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
18 |
|
19 |
@spaces.GPU
|
20 |
+
def inference(text, image):
|
21 |
+
prompt = prompt_format.format(text)
|
22 |
+
inputs = processor(prompt, image, return_tensors='pt').to(0, torch.float16)
|
23 |
+
output = model.generate(**inputs, max_new_tokens=1024)
|
24 |
+
return processor.decode(output[0][2:], skip_special_tokens=True)
|
25 |
|
26 |
+
gr.Interface(fn=inference, inputs=[gr.Text(), gr.Image()], outputs=gr.Text()).launch()
|