drishti / app.py
Golu2811's picture
Create app.py
2a280a9 verified
raw
history blame
1.43 kB
from PIL import Image
from transformers import AutoProcessor, AutoModelForPreTraining
import streamlit as st
from PIL import Image
import cv2
import requests
from dotenv import load_dotenv
import google.generativeai as genai
from langchain_google_genai import ChatGoogleGenerativeAI
import os
import pandas as pd
from huggingface_hub import login
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)
# Specify the file path to save the image
filepath = "./uploaded_image.jpg"
# Save the image
image.save(filepath)
st.success(f"Image saved successfully at {filepath}")
prompt = "Describe the image content in detail."
# Preprocess the image and prompt using the processor
inputs = processor( text=prompt, images=image, return_tensors="pt")
# Pass the inputs to the model
outputs = model(**inputs)
# Assuming you have the output stored in a variable called `outputs`
generated_text = processor.decode(outputs.logits.argmax(dim=-1)[0], skip_special_tokens=True)
print(generated_text)
st.write(generated_text)