|
|
|
from PIL import Image |
|
from transformers import AutoProcessor, AutoModelForPreTraining |
|
import streamlit as st |
|
from PIL import Image |
|
|
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd |
|
|
|
import os |
|
print(os.getenv('hftoken')) |
|
|
|
|
|
|
|
processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-224") |
|
model = AutoModelForPreTraining.from_pretrained("google/paligemma-3b-pt-224") |
|
|
|
st.title("Image segmentation and object analysis") |
|
uploaded_file = st.file_uploader("Choose an image") |
|
|
|
if uploaded_file is not None: |
|
image_data = uploaded_file.read() |
|
st.image(image_data) |
|
st.write("file uploaded") |
|
image = Image.open(uploaded_file) |
|
|
|
filepath = "./uploaded_image.jpg" |
|
|
|
image.save(filepath) |
|
st.success(f"Image saved successfully at {filepath}") |
|
prompt = "Describe the image content in detail." |
|
|
|
|
|
inputs = processor( text=prompt, images=image, return_tensors="pt") |
|
|
|
|
|
outputs = model(**inputs) |
|
|
|
generated_text = processor.decode(outputs.logits.argmax(dim=-1)[0], skip_special_tokens=True) |
|
print(generated_text) |
|
st.write(generated_text) |