What-can-go-wrong / pass2.py
dipta007's picture
added 2 passes
3b827fa
raw
history blame contribute delete
No virus
2.23 kB
from utils import im_2_b64, RANDOM_SEED, client
import streamlit as st
prompt = """
In the following task, you will be presented with some images and a story that is, in some manner, related to that goal. You will be given a specific goal, and a condition that could prevent that goal from being achieved. Using both story and images, you will be asked to identify an event that could result in that condition being true thus preventing goal success. If it is not plausible to identify such an event, you can state that as well.
Output in a python dictionary where it should have the following keys: 'event'.
Story: {story}
Goal: {goal}
Condition: {condition}
"""
def get_gpt4V_response_2(story, goal, condition, images, temperature=0.5):
# Convert image to base64
image_urls = []
for image in images:
if type(images[0]) == bytes:
image_b64 = image
image_url = f"data:image/jpeg;base64,{image_b64.decode('utf-8')}"
else:
image_b64 = im_2_b64(image)
image_url = f"data:image/jpeg;base64,{image_b64.decode('utf-8')}"
image_urls.append(image_url)
st.write("βœ… Image converted")
now_prompt = prompt.format(story=story, goal=goal, condition=condition)
content = [
{"type": "text", "text": now_prompt},
]
st.write("βœ… Prompt created")
for image_url in image_urls:
content.append({
"type": "image_url",
"image_url": {
"url": image_url,
},
})
st.write("πŸš€ Getting Response from GPT4V")
response = client.chat.completions.create(
model="gpt-4-vision-preview",
seed=RANDOM_SEED,
messages=[
{
"role": "user",
"content": content
}
],
temperature=temperature,
max_tokens=1024,
# top_p=1,
# frequency_penalty=0,
# presence_penalty=0,
)
# print(response)
# print("Prompt:")
# print(now_prompt)
out = response.choices[0].message.content
# print("OUTPUT:", out)
# print("====================================")
# print()
st.write("βœ… Response generated")
return out