abdulelahagr commited on
Commit
f27b541
·
verified ·
1 Parent(s): 6cb0936

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
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()