Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, BitsAndBytesConfig
|
3 |
+
import torch
|
4 |
+
|
5 |
+
quantization_config = BitsAndBytesConfig(
|
6 |
+
load_in_4bit=True,
|
7 |
+
bnb_4bit_compute_dtype=torch.float16
|
8 |
+
)
|
9 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
10 |
+
|
11 |
+
pipe = pipeline("image-to-text",
|
12 |
+
model=model_id)
|
13 |
+
|
14 |
+
|
15 |
+
def launch(image, prompt):
|
16 |
+
prompt = f"USER: <image>\n{prompt}\nASSISTANT:"
|
17 |
+
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
18 |
+
return out[0]['generated_text']
|
19 |
+
|
20 |
+
iface = gr.Interface(launch,
|
21 |
+
inputs=[gr.Image(type='pil'), 'text'],
|
22 |
+
outputs="text")
|
23 |
+
|
24 |
+
iface.launch()
|