nehapasricha94
commited on
Commit
•
228a778
1
Parent(s):
08f2d5f
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,23 @@ import gradio as gr
|
|
2 |
from transformers import VisionEncoderDecoderModel, AutoTokenizer
|
3 |
from PIL import Image
|
4 |
import io
|
|
|
5 |
|
6 |
-
# Load model
|
7 |
-
model =
|
8 |
-
tokenizer =
|
9 |
|
10 |
# Function to analyze the image
|
11 |
def analyze_image(image_blob):
|
12 |
image = Image.open(io.BytesIO(image_blob))
|
|
|
13 |
inputs = tokenizer("Analyze the emotions in this image", return_tensors="pt")
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Set up the Gradio interface
|
18 |
iface = gr.Interface(fn=analyze_image, inputs="file", outputs="text")
|
|
|
2 |
from transformers import VisionEncoderDecoderModel, AutoTokenizer
|
3 |
from PIL import Image
|
4 |
import io
|
5 |
+
import torch
|
6 |
|
7 |
+
# Load model and tokenizer
|
8 |
+
model = VisionEncoderDecoderModel.from_pretrained("liuhaotian/LLaVA-1.5-7b")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("liuhaotian/LLaVA-1.5-7b")
|
10 |
|
11 |
# Function to analyze the image
|
12 |
def analyze_image(image_blob):
|
13 |
image = Image.open(io.BytesIO(image_blob))
|
14 |
+
pixel_values = torch.tensor(image).unsqueeze(0) # Add batch dimension
|
15 |
inputs = tokenizer("Analyze the emotions in this image", return_tensors="pt")
|
16 |
+
|
17 |
+
# Run the model
|
18 |
+
outputs = model.generate(**inputs, pixel_values=pixel_values)
|
19 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
|
21 |
+
return result
|
22 |
|
23 |
# Set up the Gradio interface
|
24 |
iface = gr.Interface(fn=analyze_image, inputs="file", outputs="text")
|