Claudz163's picture
updated
63eb096
raw
history blame
1.37 kB
import streamlit as st
from transformers import pipeline
from PIL import Image
st.header("Character Captions")
st.write("Have a character caption any image you upload!")
character = st.selectbox("Choose a character", ["rapper", "monkey", "shrek", "unintelligible"])
uploaded_img = st.file_uploader("Upload an image")
if uploaded_img is not None:
image = Image.open(uploaded_img)
st.image(image)
image_captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
response = image_captioner(image)
caption = response[0]['generated_text']
st.write("Caption:", caption)
character_prompts = {
"rapper": f"Describe this scene like you're a rapper singing: {caption}.",
"monkey": f"Describe this scene like you're a monkey going bananas: {caption}.",
"shrek": f"Describe this scene like you're Shrek: {caption}.",
"unintelligible": f"Describe this scene in a way that makes no sense: {caption}."
}
prompt = character_prompts[character]
st.write(prompt)
# pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-Guard-2-8B")
# # Pass the caption to another model
# personality = "rapper"
# prompt = personality_prompts[personality]
# styled_caption = text_generator(prompt, max_length=100, num_return_sequences=1)
# print(styled_caption[0]["generated_text"])