Spaces:
Build error
Build error
Deploy SPACE
Browse files- app.py +21 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import BitsAndBytesConfig, pipeline
|
4 |
+
|
5 |
+
# Load model directly
|
6 |
+
quantization_config = BitsAndBytesConfig(
|
7 |
+
load_in_4bit=True,
|
8 |
+
bnb_4bit_compute_dtype=torch.float16
|
9 |
+
)
|
10 |
+
|
11 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
12 |
+
pipe = pipeline("image-to-text", model=model_id, model_kwargs={"quantization_config": quantization_config})
|
13 |
+
|
14 |
+
def generate_text(image):
|
15 |
+
max_new_tokens = 200
|
16 |
+
prompt = "USER: <image>\nWhat are the things I should be cautious about when I visit this place?\nASSISTANT:"
|
17 |
+
outputs = pipe(image, prompt=prompt, generate_kwargs={"max_new_tokens": 200})
|
18 |
+
return outputs[0]["generated_text"]
|
19 |
+
|
20 |
+
iface = gr.Interface(fn=generate_text, inputs=gr.inputs.Image(), outputs="text")
|
21 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers==4.37.2
|
2 |
+
bitsandbytes==0.41.3
|
3 |
+
accelerate==0.25.0
|
4 |
+
gradio
|